]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fundamental-macro: conditionalize several gcc warning pragmas 36051/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 16 Jan 2025 19:27:36 +0000 (04:27 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 16 Jan 2025 19:35:09 +0000 (04:35 +0900)
This fixes the following error:

In file included from ../src/basic/macro.h:13,
                 from ../src/basic/env-util.h:9,
                 from ../src/nss-systemd/nss-systemd.c:7:
../src/fundamental/macro-fundamental.h:61:9: error: option ‘-Wzero-as-null-pointer-constant’ is valid for C++/ObjC++ but not for C [-Werror=pragmas]
   61 |         _Pragma("GCC diagnostic ignored \"-Wzero-as-null-pointer-constant\"")
      |         ^~~~~~~
../src/nss-systemd/nss-systemd.c:106:1: note: in expansion of macro ‘DISABLE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT’
  106 | DISABLE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT;
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

meson.build
src/boot/meson.build
src/fundamental/macro-fundamental.h

index f9f400a7d64bd2c1e73cf5f2b155a98210a4eea3..48ba967d0ee52aca83eeaddaacfcfb79f9dcadc4 100644 (file)
@@ -516,9 +516,6 @@ add_project_link_arguments(
 userspace_c_args += cc.get_supported_arguments(possible_cc_flags)
 userspace_c_ld_args += cc.get_supported_link_arguments(possible_link_flags)
 
-have = cc.has_argument('-Wzero-length-bounds')
-conf.set10('HAVE_ZERO_LENGTH_BOUNDS', have)
-
 if cc.compiles('''
    #include <time.h>
    #include <inttypes.h>
@@ -538,6 +535,14 @@ endif
 
 cpp = ' '.join(cc.cmd_array() + get_option('c_args')) + ' -E'
 
+# new in GCC 10
+have = cc.has_argument('-Wzero-length-bounds')
+conf.set10('HAVE_WARNING_ZERO_LENGTH_BOUNDS', have)
+
+# new in GCC 15
+have = cc.has_argument('-Wzero-as-null-pointer-constant')
+conf.set10('HAVE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT', have)
+
 #####################################################################
 # compilation result tests
 
index cc5102c5518849dc01a763077047509fe3a38453..f7269962334222487c2824d8004171fa99771912 100644 (file)
@@ -74,6 +74,12 @@ if conf.get('ENABLE_BOOTLOADER') != 1
 endif
 
 efi_conf = configuration_data()
+
+# import several configs from userspace
+foreach name : ['HAVE_WARNING_ZERO_LENGTH_BOUNDS', 'HAVE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT']
+        efi_conf.set10(name, conf.get(name) == 1)
+endforeach
+
 efi_conf.set10('ENABLE_TPM', get_option('tpm'))
 
 foreach ctype : ['color-normal', 'color-entry', 'color-highlight', 'color-edit']
index 7bee2915e1b255a2bae80c857197ce5fb098350c..5eb31cd74283d623ac971721dd652906a66e1028 100644 (file)
         _Pragma("GCC diagnostic push");                                 \
         _Pragma("GCC diagnostic ignored \"-Wstringop-truncation\"")
 
-#define DISABLE_WARNING_ZERO_LENGTH_BOUNDS                              \
+#if HAVE_WARNING_ZERO_LENGTH_BOUNDS
+#  define DISABLE_WARNING_ZERO_LENGTH_BOUNDS                            \
         _Pragma("GCC diagnostic push");                                 \
         _Pragma("GCC diagnostic ignored \"-Wzero-length-bounds\"")
+#else
+#  define DISABLE_WARNING_ZERO_LENGTH_BOUNDS                            \
+        _Pragma("GCC diagnostic push")
+#endif
 
-#define DISABLE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT                   \
+#if HAVE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT
+#  define DISABLE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT                 \
         _Pragma("GCC diagnostic push");                                 \
         _Pragma("GCC diagnostic ignored \"-Wzero-as-null-pointer-constant\"")
+#else
+#  define DISABLE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT                 \
+        _Pragma("GCC diagnostic push")
+#endif
 
 #define REENABLE_WARNING                                                \
         _Pragma("GCC diagnostic pop")