On 12/15/2017 10:49 AM, Bruno Haible wrote:
> Tim Rühsen wrote:
>> It works, but... ;-)
> 
> OK, I've pushed it.
> 
>> Your patch disables that warning for the whole file. IMO, we should keep
>> the scope of the #pragma as narrow as possible.
>>
>> We could have a pragma.h include file with the following C99 code (I
>> leave the clang and gcc version checks to you):
>>
>> #define STRINGIFY(a) #a
>>
>> #if defined __clang__
>> # define NOWARN(a) _Pragma( STRINGIFY( clang diagnostic ignored a ) )
>> # define NOWARN_PUSH(a) \
>>   _Pragma( STRINGIFY( clang diagnostic push ) ) \
>>   _Pragma( STRINGIFY( clang diagnostic ignored a ) )
>> # define NOWARN_POP _Pragma( STRINGIFY( gcc diagnostic pop ) )
>> #elif defined __GNUC__
>> # define NOWARN(a) _Pragma( STRINGIFY( gcc diagnostic ignored a ) )
>> # define NOWARN_PUSH(a) \
>>   _Pragma( STRINGIFY( gcc diagnostic push ) ) \
>>   _Pragma( STRINGIFY( gcc diagnostic ignored a ) )
>> # define NOWARN_POP _Pragma( STRINGIFY( gcc diagnostic pop ) )
>> #else
>> # define NOWARN
>> # define NOWARN_PUSH
>> # define NOWARN_POP
>> #endif
> 
> Indeed such macrology belongs in one single file. Would you like to provide
> a patch?

Attached is a quick commit with a new lib/pragmas.h. Sorry, I currently
don't have time for anything more (e.g. a module).

> The macros should cater for the case the gcc and clang have different warning
> options (see e.g. anytostr.c).

Added a pragma to silence clang on unknown options. gcc doesn't complain
anyways. So if we need two different options, just use both.

> Also if NOWARN and NOWARN_PUSH take an argument in one case, they need to take
> an argument in the #else case as well.

Fixed.

Regards, Tim
From 63a2a7d9bf8d3a5c479dea400ca334720a30f32b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tim=20R=C3=BChsen?= <tim.rueh...@gmx.de>
Date: Fri, 15 Dec 2017 11:32:32 +0100
Subject: [PATCH] lib/pragmas.h: Define for controlling compiler warning
 options

---
 lib/pragmas.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 lib/pragmas.h

diff --git a/lib/pragmas.h b/lib/pragmas.h
new file mode 100644
index 000000000..459245dd1
--- /dev/null
+++ b/lib/pragmas.h
@@ -0,0 +1,54 @@
+/* Defines for controlling compiler warnings
+
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+#ifndef PRAGMAS_H_
+# define PRAGMAS_H_ 1
+
+/* file local stringify, undef'ed after use */
+#define GL_STRINGIFY(a) #a
+
+#if defined __clang__
+
+# define NOWARN(a) _Pragma( GL_STRINGIFY( clang diagnostic ignored a ) )
+# define NOWARN_PUSH(a) \
+  _Pragma( GL_STRINGIFY( clang diagnostic push ) ) \
+  _Pragma( GL_STRINGIFY( clang diagnostic ignored a ) )
+# define NOWARN_POP _Pragma( GL_STRINGIFY( gcc diagnostic pop ) )
+
+  /* clang complains about unknown options in diagnostic pragmas,
+     gcc doesn't. */
+  NOWARN("-Wunknown-warning-option")
+
+#elif defined __GNUC__ && ( __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 5 ) )
+
+# define NOWARN(a) _Pragma( GL_STRINGIFY( gcc diagnostic ignored a ) )
+# define NOWARN_PUSH(a) \
+  _Pragma( GL_STRINGIFY( gcc diagnostic push ) ) \
+  _Pragma( GL_STRINGIFY( gcc diagnostic ignored a ) )
+# define NOWARN_POP _Pragma( GL_STRINGIFY( gcc diagnostic pop ) )
+
+#else
+
+# define NOWARN(a)
+# define NOWARN_PUSH(a)
+# define NOWARN_POP
+
+#endif
+
+#undef GL_STRINGIFY
+
+#endif /* PRAGMAS_H_ */
-- 
2.15.1

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to