grub-devel
[Top][All Lists]
Advanced

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

Re: Disable -Werror when error attribute generates warnings


From: Colin Watson
Subject: Re: Disable -Werror when error attribute generates warnings
Date: Sat, 2 Jan 2010 15:37:38 +0000
User-agent: Mutt/1.5.18 (2008-05-17)

On Sat, Jan 02, 2010 at 01:58:20PM +0100, Grégoire Sutre wrote:
> With an older version of gcc that does not understand the error  
> attribute, gcc generates warnings when compiling files that include  
> include/grub/list.h.  Since TARGET_CFLAGS contains -Werror by default,  
> the build of modules fails.
>
> The following patch checks whether the C compiler supports the error  
> attribute without warning, and disables -Werror if that is not the case  
> (as otherwise the build will fail).

Instead of this, why not only use the attribute if it's available? I
couldn't find an entry about it in GCC's human-readable change
summaries, but support was committed on 2007-09-23 so I think it's
available from GCC 4.3.

I use this GNUC_PREREQ approach in other projects and rather like it. It
could be extended to cover our other uses of attributes quite easily.

2010-01-02  Colin Watson  <address@hidden>

        * include/grub/misc.h (GNUC_PREREQ): New macro.
        (ATTRIBUTE_ERROR): New macro.
        * include/grub/list.h (grub_bad_type_cast_real): Use
        ATTRIBUTE_ERROR.

=== modified file 'include/grub/list.h'
--- include/grub/list.h 2009-12-31 14:03:09 +0000
+++ include/grub/list.h 2010-01-02 15:31:44 +0000
@@ -42,7 +42,7 @@ void EXPORT_FUNC(grub_list_insert) (grub
 
 static inline void *
 grub_bad_type_cast_real (int line, const char *file)
-     __attribute__ ((error ("bad type cast between incompatible grub types")));
+     ATTRIBUTE_ERROR ("bad type cast between incompatible grub types");
 
 static inline void *
 grub_bad_type_cast_real (int line, const char *file)

=== modified file 'include/grub/misc.h'
--- include/grub/misc.h 2009-12-18 02:57:32 +0000
+++ include/grub/misc.h 2010-01-02 15:31:31 +0000
@@ -25,6 +25,22 @@
 #include <grub/symbol.h>
 #include <grub/err.h>
 
+/* GCC version checking borrowed from glibc. */
+#if defined(__GNUC__) && defined(__GNUC_MINOR__)
+#  define GNUC_PREREQ(maj,min) \
+       ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
+#else
+#  define GNUC_PREREQ(maj,min) 0
+#endif
+
+/* Does this compiler support compile-time error attributes? */
+#if GNUC_PREREQ(4,3)
+#  define ATTRIBUTE_ERROR(msg) \
+       __attribute__ ((__error__ (msg)))
+#else
+#  define ATTRIBUTE_ERROR(msg)
+#endif
+
 #define ALIGN_UP(addr, align) \
        ((addr + (typeof (addr)) align - 1) & ~((typeof (addr)) align - 1))
 #define ARRAY_SIZE(array) (sizeof (array) / sizeof (array[0]))

-- 
Colin Watson                                       address@hidden




reply via email to

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