diff options
| author | Michael Vogt <mvo@ubuntu.com> | 2023-08-16 18:31:23 +0200 |
|---|---|---|
| committer | Michael Vogt <mvo@ubuntu.com> | 2023-08-16 20:01:29 +0200 |
| commit | d5d227012bc8d841cccfe345a0b9214e6f82a23b (patch) | |
| tree | 820fa3100fc5be1c05cc848fa14b0dcac2626f4e | |
| parent | c2e71874f10c2971260a28d423898da714deb190 (diff) | |
cmd: detect if -Wno-missing-field-initializers is neededdetect-broken-gcc-missing-field-initializers
Older versions of gcc are buggy and will give incorrect errors when using `-Wmissing-field-initializers`. This is true on e.g. 14.04 and 16.04. However this is relatively straightforward to detect and the configure.ac snippet in this commit will take care of it.
| -rw-r--r-- | cmd/Makefile.am | 4 | ||||
| -rw-r--r-- | cmd/configure.ac | 17 |
2 files changed, 21 insertions, 0 deletions
diff --git a/cmd/Makefile.am b/cmd/Makefile.am index cf246fadb9..5d490fa28d 100644 --- a/cmd/Makefile.am +++ b/cmd/Makefile.am @@ -10,6 +10,10 @@ noinst_LIBRARIES = CHECK_CFLAGS = -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes \ -Wno-unused-parameter +if NO_MISSING_FIELD_INITIALIZERS +CHECK_CFLAGS += -Wno-missing-field-initializers +endif + # Make all warnings errors when building for unit tests if WITH_UNIT_TESTS CHECK_CFLAGS += -Werror diff --git a/cmd/configure.ac b/cmd/configure.ac index b9c76a9ab7..fc1f4b0f7d 100644 --- a/cmd/configure.ac +++ b/cmd/configure.ac @@ -257,5 +257,22 @@ fi fi AM_CONDITIONAL([USE_INTERNAL_BPF_HEADERS], [test "x$host_bpf_headers_usable" = "xno"]) +AC_DEFINE([MISSING_FIELD_INITIALIZERS_USABLE], [1], [-Wmissing-field-initializers are usable]) +AC_MSG_CHECKING([whether MISSING_FIELD_INITIALIZER warnings are usable]) +AC_COMPILE_IFELSE([ +#include <linux/resource.h> +#pragma GCC diagnostic error "-Wmissing-field-initializers" +struct sc_mount{const char *path;int foo;}; +void foo() { struct sc_mount mounts[[]] = { {.path = "x"}, {}, }; } +void bar() { struct rlimit limit = {0}; } +], [w_missing_field_initializers_usable=yes], [w_missing_field_initializers_usable=no]) +if test "x$w_missing_field_initializers_usable" = "xyes"; then + AC_MSG_RESULT([yes]) +else + AC_MSG_RESULT([no, running with -Wno-missing-field-initializers]) +fi +AM_CONDITIONAL([NO_MISSING_FIELD_INITIALIZERS], [test "x$w_missing_field_initializers_usable" = "xno"]) + + AC_CONFIG_FILES([Makefile]) AC_OUTPUT |
