bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: avoid gcc 4.6.2 'may be used before set' warnings in dfa.c


From: Paul Eggert
Subject: Re: avoid gcc 4.6.2 'may be used before set' warnings in dfa.c
Date: Fri, 24 Feb 2012 17:30:54 -0800
User-agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2

How about going with this patch to address this issue in grep's
source code?  It uses C11's <stdnoreturn.h>, falling back on a
simple gnulib substitute for pre-C11 compilers.
If Awk doesn't use gnulib, Awk can use the stdnoreturn.h
file that this patch builds, which I can email if you like.

>From fdfa5e9132ca3c57814d752349f4a9a7eeacf573 Mon Sep 17 00:00:00 2001
From: Paul Eggert <address@hidden>
Date: Fri, 24 Feb 2012 17:25:50 -0800
Subject: [PATCH] maint: use stdnoreturn.h rather than rolling our own

* bootstrap.conf (gnulib_modules): Add stdnoreturn.
* src/grep.h (__attribute__): Remove.
* src/dfa.h (__attribute__): Likewise.
Include <stdnoreturn.h>.
(dfaerror): Use noreturn rather than __attribute__ ((noreturn)).
* src/dfa.h, src/system.h: Include <stdnoreturn.h>.
* src/main.c (usage): Likewise.
---
 bootstrap.conf |    1 +
 src/dfa.h      |    6 ++----
 src/grep.h     |    4 ----
 src/main.c     |    3 +--
 src/system.h   |    1 +
 5 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index 2b7a5ec..7400359 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -68,6 +68,7 @@ same-inode
 ssize_t
 stddef
 stdlib
+stdnoreturn
 stpcpy
 strerror
 string
diff --git a/src/dfa.h b/src/dfa.h
index 17a4778..f0b2de9 100644
--- a/src/dfa.h
+++ b/src/dfa.h
@@ -18,9 +18,7 @@
 
 /* Written June, 1988 by Mike Haertel */
 
-#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6) || __STRICT_ANSI__
-# define __attribute__(x)
-#endif
+#include <stdnoreturn.h>
 
 /* Element of a list of strings, at least one of which is known to
    appear in any R.E. matching the DFA. */
@@ -99,4 +97,4 @@ extern void dfawarn (const char *);
 /* dfaerror() is called by the regexp routines whenever an error occurs.  It
    takes a single argument, a NUL-terminated string describing the error.
    The user must supply a dfaerror.  */
-extern void dfaerror (const char *) __attribute__ ((noreturn));
+extern noreturn void dfaerror (const char *);
diff --git a/src/grep.h b/src/grep.h
index 744a889..f5ab8bf 100644
--- a/src/grep.h
+++ b/src/grep.h
@@ -20,10 +20,6 @@
 #ifndef GREP_GREP_H
 #define GREP_GREP_H 1
 
-#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6) || __STRICT_ANSI__
-# define __attribute__(x)
-#endif
-
 /* Function pointer types.  */
 typedef void (*compile_fp_t) (char const *, size_t);
 typedef size_t (*execute_fp_t) (char const *, size_t, size_t *, char const *);
diff --git a/src/main.c b/src/main.c
index e593871..8b3f7bc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1432,8 +1432,7 @@ grepdir (char const *dir, struct stats const *stats)
   return status;
 }
 
-void usage (int status) __attribute__ ((noreturn));
-void
+void noreturn
 usage (int status)
 {
   if (status != 0)
diff --git a/src/system.h b/src/system.h
index 426d893..baeae3a 100644
--- a/src/system.h
+++ b/src/system.h
@@ -35,6 +35,7 @@
 
 #include <stdlib.h>
 #include <stddef.h>
+#include <stdnoreturn.h>
 #include <limits.h>
 #include <string.h>
 #include <ctype.h>
-- 
1.7.6.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]