[dm-devel] [PATCH 70/72] multipath tests: Makefile: avoid gcc 4.8 missing initializers failure

Martin Wilck Martin.Wilck at suse.com
Sat Oct 12 21:29:04 UTC 2019


From: Martin Wilck <mwilck at suse.com>

With -Wmissing-field-initializers (implied by our current compiler flags),
gcc 4.8 errors out if nested initializers are missing:

struct A {
       int a, b;
};

struct B {
       struct A a;
       int c;
} b = { .a.a = 1; }

Later gcc versions and clang accept it just fine.
Add a test to tests/Makefile and use -Wno-missing-initializers if gcc 4.8
behavior is detected.

Signed-off-by: Martin Wilck <mwilck at suse.com>
---
 tests/Makefile | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/tests/Makefile b/tests/Makefile
index c70b8399..c9406e75 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,6 +1,15 @@
 include ../Makefile.inc
 
-CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathcmddir) -Wno-unused-parameter
+# Test special behavior of gcc 4.8 with nested initializers
+# gcc 4.8 compiles blacklist.c only with -Wno-missing-field-initializers
+TEST_MISSING_INITIALIZERS = $(shell \
+	echo 'struct A {int a, b;}; struct B {struct A a; int b;} b = {.a.a=1};' | \
+		$(CC) -c -Werror -Wmissing-field-initializers -o /dev/null -xc - >/dev/null 2>&1 \
+	|| echo -Wno-missing-field-initializers)
+W_MISSING_INITIALIZERS := $(call TEST_MISSING_INITIALIZERS)
+
+CFLAGS += $(BIN_CFLAGS) -I$(multipathdir) -I$(mpathcmddir) \
+	-Wno-unused-parameter $(W_MISSING_INITIALIZERS)
 LIBDEPS += -L$(multipathdir) -lmultipath -lcmocka
 
 TESTS := uevent parser util dmevents hwtable blacklist unaligned vpd pgpolicy alias
-- 
2.23.0





More information about the dm-devel mailing list