[libvirt] [PATCH v2 42/42] m4: enable the -Wswitch-default warning flag

Daniel P. Berrangé berrange at redhat.com
Thu Feb 15 16:43:47 UTC 2018


Even if the compiler has validated that all enum constants have case
statements in a switch, it is not safe to omit a default: case
statement. When assigning a value to a variable / struct field that is
defined with an enum type, nothing prevents an invalid value being
assigned. So defensive code must assume existance of invalid values and
thus all switches should have a default: case.

This enables the -Wswitch-default compiler warning flag which will now
enforce this requirement.

Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
---
 m4/virt-compile-warnings.m4 | 2 --
 1 file changed, 2 deletions(-)

diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4
index fc185aef38..216a3ee0e9 100644
--- a/m4/virt-compile-warnings.m4
+++ b/m4/virt-compile-warnings.m4
@@ -45,8 +45,6 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
     dontwarn="$dontwarn -Wcast-qual"
     # We need to use long long in many places
     dontwarn="$dontwarn -Wlong-long"
-    # We allow manual list of all enum cases without default:
-    dontwarn="$dontwarn -Wswitch-default"
     # 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
-- 
2.14.3




More information about the libvir-list mailing list