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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 m4/virt-compile-warnings.m4 | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4
index b9c9748420..918764d362 100644
--- a/m4/virt-compile-warnings.m4
+++ b/m4/virt-compile-warnings.m4
@@ -47,8 +47,6 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
     dontwarn="$dontwarn -Wlong-long"
     # We allow manual list of all enum cases without default:
     dontwarn="$dontwarn -Wswitch-default"
-    # We allow optional default: instead of listing all enum values
-    dontwarn="$dontwarn -Wswitch-enum"
     # Not a problem since we don't use -fstrict-overflow
     dontwarn="$dontwarn -Wstrict-overflow"
     # Not a problem since we don't use -funsafe-loop-optimizations
@@ -182,6 +180,11 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
     # that one off, so we need to manually enable this again
     wantwarn="$wantwarn -Wjump-misses-init"
 
+    # GNULIB explicitly filters it out, preferring -Wswitch
+    # but that doesn't report missing enums if a default:
+    # is present.
+    wantwarn="$wantwarn -Wswitch-enum"
+
     # GNULIB turns on -Wformat=2 which implies -Wformat-nonliteral,
     # so we need to manually re-exclude it.  Also, older gcc 4.2
     # added an implied ATTRIBUTE_NONNULL on any parameter marked
-- 
2.14.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux