openal-soft icon indicating copy to clipboard operation
openal-soft copied to clipboard

[Question] Is there any reason why SND_PCM_STATE_PRIVATE1 enumeration value unhandled?

Open runlevel5 opened this issue 1 year ago • 2 comments

/__w/Q2RTX/Q2RTX/extern/openal-soft/alc/backends/alsa.cpp:396:11: warning: enumeration value 'SND_PCM_STATE_PRIVATE1' not handled in switch [-Wswitch]
  396 |     switch(state)
      |           ^

The compiler gives me that warning and so it's seems to me SND_PCM_STATE_PRIVATE1 is not handled. Is it by intention?

runlevel5 avatar May 01 '24 23:05 runlevel5

As it's name suggests, it's a private state enumeration, that shouldn't be used by callers.

/** Private - used internally in the library - do not use*/
SND_PCM_STATE_PRIVATE1 = 1024

Unfortunately it being placed in the public headers means the compiler can see it as a potential enumeration for snd_pcm_state_t variables, which the compiler expectedly warns about not being handled as a potential value. I'd really consider this a bug in ALSA's headers, making a private thing public that causes errant warnings in valid properly written code. The only ways to avoid it are either to use it, in opposition to the comment, or disable -Wswitch warnings (or add a default case for the same effect), which can hide bugs from unhandled public enum states that may be added in the future (or other changes that could cause an existing state to not be handled as it should be).

kcat avatar May 02 '24 01:05 kcat

disable -Wswitch warnings

Not a good idea I agree.

either to use it, in opposition to the comment

Perhaps we should handle it and raise an error to let our devs know it is not meant to be used?

runlevel5 avatar May 02 '24 02:05 runlevel5

This was fixed with commit c05fc028d378801f4abe16eba212e033a388ca70.

kcat avatar Nov 13 '24 04:11 kcat