[libvirt] [PATCH v2 14/42] m4: enforce that all enum cases are listed in switch statements

John Ferlan jferlan at redhat.com
Mon Feb 19 21:21:23 UTC 2018



On 02/15/2018 11:43 AM, Daniel P. Berrangé wrote:
> As a general rule any time we switch() on something that is an enum, we
> want to have a case for every enum constant. The -Wswitch warning will
> report any switch where we've violated this rule, except if that switch
> has a default case.
> 
> Unfortunately it is reasonable to want to list all enum constants *and*
> also have a default case. To get a warning in that scenario requires
> that we turn on -Wswitch-enum.
> 
> In a few cases where we explicitly don't want to list all enum cases, we
> can discard the enum type checking by casting the value to a plain int.
> 
> Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
> ---
>  m4/virt-compile-warnings.m4 | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 

Reviewed-by: John Ferlan <jferlan at redhat.com>

John




More information about the libvir-list mailing list