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: Sun, 26 Feb 2012 11:31:50 -0800
User-agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2

On 02/26/2012 01:18 AM, address@hidden wrote:
> It looks like I can just use the code as it is now in grep. I have asked
> for compile failures and haven't gotten any.

Sure, but the gnulib support for this is better
than what's in the dfa code.  It could be that
your correspondents aren't using the less-common hosts
or compiler warning options that gnulib is ported to.

In the long run stdnoreturn.h or _Noreturn is the way to go,
since they're part of the C standard.

If you'd rather not create a separate file, how about if
we change the dfa code to use _Noreturn instead of
<stdnoreturn.h> and noreturn, and you can put the
following into your configure.ac so that config.h
defines _Noreturn the same way gnulib does:

AH_VERBATIM([_Noreturn],
[/* The _Noreturn keyword of C11.  */
#ifndef _Noreturn                                                               
# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \                 
      || 0x5110 <= __SUNPRO_C)
#  define _Noreturn __attribute__ ((__noreturn__))                              
# elif defined _MSC_VER && 1200 <= _MSC_VER                                     
#  define _Noreturn __declspec (noreturn)                                       
# else                                                                          
#  define _Noreturn                                                             
# endif                                                                         
#endif                                                                          
])


Here's a patch to 'grep' that would implement this idea.
I don't have a strong feeling about this versus the
<stdnoreturn.h> patch; either would be OK with me.

>From 09ee44ff05019961930c326a6067ed5556914634 Mon Sep 17 00:00:00 2001
From: Paul Eggert <address@hidden>
Date: Sun, 26 Feb 2012 11:28:37 -0800
Subject: [PATCH] maint: use gnulib _Noreturn rather than __attribute__
 ((noreturn))

* src/grep.h (__attribute__): Remove.
* src/dfa.h (__attribute__): Likewise.
(dfaerror): Use noreturn rather than __attribute__ ((noreturn)).
* src/main.c (usage): Likewise.
---
 src/dfa.h  |    6 +-----
 src/grep.h |    4 ----
 src/main.c |    3 +--
 3 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/src/dfa.h b/src/dfa.h
index 17a4778..351a470 100644
--- a/src/dfa.h
+++ b/src/dfa.h
@@ -18,10 +18,6 @@
 
 /* Written June, 1988 by Mike Haertel */
 
-#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6) || __STRICT_ANSI__
-# define __attribute__(x)
-#endif
-
 /* Element of a list of strings, at least one of which is known to
    appear in any R.E. matching the DFA. */
 struct dfamust
@@ -99,4 +95,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..86befba 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
+_Noreturn void
 usage (int status)
 {
   if (status != 0)
-- 
1.7.6.5

Attachment: stdnoreturn.h
Description: Text Data


reply via email to

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