Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1NR633-00011q-J1 for mharc-grub-devel@gnu.org; Sat, 02 Jan 2010 10:37:49 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NR631-00011a-8e for grub-devel@gnu.org; Sat, 02 Jan 2010 10:37:47 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NR62v-0000zg-E4 for grub-devel@gnu.org; Sat, 02 Jan 2010 10:37:45 -0500 Received: from [199.232.76.173] (port=60721 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NR62v-0000zd-3z for grub-devel@gnu.org; Sat, 02 Jan 2010 10:37:41 -0500 Received: from smarthost03.mail.zen.net.uk ([212.23.3.142]:48842) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NR62u-0008V8-Vj for grub-devel@gnu.org; Sat, 02 Jan 2010 10:37:41 -0500 Received: from [82.69.40.219] (helo=riva.pelham.vpn.ucam.org) by smarthost03.mail.zen.net.uk with esmtp (Exim 4.63) (envelope-from ) id 1NR62s-0004gL-SU for grub-devel@gnu.org; Sat, 02 Jan 2010 15:37:38 +0000 Received: from cjwatson by riva.pelham.vpn.ucam.org with local (Exim 3.36 #1 (Debian)) for grub-devel@gnu.org id 1NR62s-0008AT-00; Sat, 02 Jan 2010 15:37:38 +0000 Date: Sat, 2 Jan 2010 15:37:38 +0000 From: Colin Watson To: grub-devel@gnu.org Message-ID: <20100102153738.GX5847@riva.ucam.org> References: <4B3F42EC.1010100@labri.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4B3F42EC.1010100@labri.fr> User-Agent: Mutt/1.5.18 (2008-05-17) X-Originating-Smarthost03-IP: [82.69.40.219] X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: Re: Disable -Werror when error attribute generates warnings X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Jan 2010 15:37:48 -0000 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 * 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 #include +/* 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 [cjwatson@ubuntu.com]