[PATCH 2/2] Ignore missing braces error for GCC 4.9 or older

H.J. Lu hjl.tools@gmail.com
Sun Dec 15 12:09:57 GMT 2024


Since not all targets need braces, ignore missing braces error for GCC
4.9 or older:

tst-system.c: In function ‘sleep_and_check_sigchld’:
tst-system.c:83:3: error: missing braces around initializer [-Werror=missing-braces]
   sigset_t blocked = {0};
   ^
tst-system.c:83:3: error: (near initialization for ‘blocked.__val’) [-Werror=missing-braces]
cc1: all warnings being treated as errors

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
 posix/tst-spawn7.c             | 15 +++++++++++++++
 rt/tst-timer-sigmask.c         | 15 +++++++++++++++
 stdlib/tst-system.c            |  8 ++++++++
 sysdeps/pthread/tst-cancel28.c | 15 +++++++++++++++
 4 files changed, 53 insertions(+)

diff --git a/posix/tst-spawn7.c b/posix/tst-spawn7.c
index e4adc6cbf0..14b755081c 100644
--- a/posix/tst-spawn7.c
+++ b/posix/tst-spawn7.c
@@ -27,6 +27,7 @@
 #include <sys/wait.h>
 #include <unistd.h>
 #include <tst-spawn.h>
+#include <libc-diag.h>
 
 /* Nonzero if the program gets called via `exec'.  */
 #define CMDLINE_OPTIONS \
@@ -114,7 +115,14 @@ do_test_signals (void)
   {
     /* Same as before, but set SIGUSR1 and SIGUSR2 to a handler different than
        SIG_IGN or SIG_DFL.  */
+#if !__GNUC_PREREQ (5, 0)
+    DIAG_PUSH_NEEDS_COMMENT;
+    DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wmissing-braces");
+#endif
     struct sigaction sa = { 0 };
+#if !__GNUC_PREREQ (5, 0)
+    DIAG_POP_NEEDS_COMMENT;
+#endif
     sa.sa_handler = dummy_sa_handler;
     xsigaction (SIGUSR1, &sa, NULL);
     xsigaction (SIGUSR2, &sa, NULL);
@@ -123,7 +131,14 @@ do_test_signals (void)
 
   {
     /* Check if SIG_IGN is keep as is.  */
+#if !__GNUC_PREREQ (5, 0)
+    DIAG_PUSH_NEEDS_COMMENT;
+    DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wmissing-braces");
+#endif
     struct sigaction sa = { 0 };
+#if !__GNUC_PREREQ (5, 0)
+    DIAG_POP_NEEDS_COMMENT;
+#endif
     sa.sa_handler = SIG_IGN;
     xsigaction (SIGUSR1, &sa, NULL);
     xsigaction (SIGUSR2, &sa, NULL);
diff --git a/rt/tst-timer-sigmask.c b/rt/tst-timer-sigmask.c
index e27b2e5189..b058ecea64 100644
--- a/rt/tst-timer-sigmask.c
+++ b/rt/tst-timer-sigmask.c
@@ -20,6 +20,7 @@
 #include <time.h>
 #include <signal.h>
 #include <stdbool.h>
+#include <libc-diag.h>
 
 #include <support/check.h>
 #include <support/test-driver.h>
@@ -57,7 +58,14 @@ thread_handler (union sigval sv)
 static int
 do_test (void)
 {
+#if !__GNUC_PREREQ (5, 0)
+    DIAG_PUSH_NEEDS_COMMENT;
+    DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wmissing-braces");
+#endif
   struct sigevent sev = { 0 };
+#if !__GNUC_PREREQ (5, 0)
+    DIAG_POP_NEEDS_COMMENT;
+#endif
   sev.sigev_notify = SIGEV_THREAD;
   sev.sigev_notify_function = &thread_handler;
 
@@ -66,7 +74,14 @@ do_test (void)
 
   xpthread_barrier_init (&barrier, NULL, 2);
 
+#if !__GNUC_PREREQ (5, 0)
+    DIAG_PUSH_NEEDS_COMMENT;
+    DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wmissing-braces");
+#endif
   struct itimerspec trigger = { 0 };
+#if !__GNUC_PREREQ (5, 0)
+    DIAG_POP_NEEDS_COMMENT;
+#endif
   trigger.it_value.tv_nsec = 1000000;
   TEST_COMPARE (timer_settime (timerid, 0, &trigger, NULL), 0);
 
diff --git a/stdlib/tst-system.c b/stdlib/tst-system.c
index b5b630a41b..fe30dbc330 100644
--- a/stdlib/tst-system.c
+++ b/stdlib/tst-system.c
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <signal.h>
 #include <paths.h>
+#include <libc-diag.h>
 
 #include <support/capture_subprocess.h>
 #include <support/check.h>
@@ -80,7 +81,14 @@ sleep_and_check_sigchld (void *closure)
   sprintf (cmd, "sleep %lf" , *seconds);
   TEST_COMPARE (system (cmd), 0);
 
+#if !__GNUC_PREREQ (5, 0)
+    DIAG_PUSH_NEEDS_COMMENT;
+    DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wmissing-braces");
+#endif
   sigset_t blocked = {0};
+#if !__GNUC_PREREQ (5, 0)
+    DIAG_POP_NEEDS_COMMENT;
+#endif
   TEST_COMPARE (sigprocmask (SIG_BLOCK, NULL, &blocked), 0);
   TEST_COMPARE (sigismember (&blocked, SIGCHLD), 0);
   return NULL;
diff --git a/sysdeps/pthread/tst-cancel28.c b/sysdeps/pthread/tst-cancel28.c
index 2280d57722..722ee738bc 100644
--- a/sysdeps/pthread/tst-cancel28.c
+++ b/sysdeps/pthread/tst-cancel28.c
@@ -22,6 +22,7 @@
 #include <signal.h>
 #include <unistd.h>
 #include <stdbool.h>
+#include <libc-diag.h>
 
 #include <support/check.h>
 #include <support/test-driver.h>
@@ -52,7 +53,14 @@ thread_handler (union sigval sv)
 static int
 do_test (void)
 {
+#if !__GNUC_PREREQ (5, 0)
+    DIAG_PUSH_NEEDS_COMMENT;
+    DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wmissing-braces");
+#endif
   struct sigevent sev = { 0 };
+#if !__GNUC_PREREQ (5, 0)
+    DIAG_POP_NEEDS_COMMENT;
+#endif
   sev.sigev_notify = SIGEV_THREAD;
   sev.sigev_notify_function = &thread_handler;
 
@@ -61,7 +69,14 @@ do_test (void)
 
   xpthread_barrier_init (&barrier, NULL, 2);
 
+#if !__GNUC_PREREQ (5, 0)
+    DIAG_PUSH_NEEDS_COMMENT;
+    DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wmissing-braces");
+#endif
   struct itimerspec trigger = { 0 };
+#if !__GNUC_PREREQ (5, 0)
+    DIAG_POP_NEEDS_COMMENT;
+#endif
   trigger.it_value.tv_nsec = 1000000;
   TEST_COMPARE (timer_settime (timerid, 0, &trigger, NULL), 0);
 
-- 
2.47.1



More information about the Libc-alpha mailing list