chiark / gitweb /
macro: add DISABLE_WARNING_SHADOW
authorDavid Herrmann <dh.herrmann@gmail.com>
Thu, 12 Jun 2014 15:54:48 +0000 (17:54 +0200)
committerDavid Herrmann <dh.herrmann@gmail.com>
Mon, 16 Jun 2014 13:22:46 +0000 (15:22 +0200)
As it turns out, we cannot use _Pragma in compound-statements. Therefore,
constructs like MIN(MAX(a, b), x) will warn due to shadowed variable
declarations. The DISABLE_WARNING_SHADOW macro can be used to suppress
these.

Note that using UNIQUE(_var) does not work either as GCC uses the last
line of a macro-expansion for __LINE__, therefore, still causing both
macros to have the same variables. We could use different variable-names
for MIN and MAX, but that just hides the problem and still fails for
MIN(something(MIN(a, b)), c).

The only working solution is to use __COUNTER__ and pass it pre-evaluated
as extra argument to a macro to use as name-prefix. This, however, makes
all these macros much more complicated so I'll go with manual
DISABLE_WARNING_SHADOW so far.

src/shared/macro.h

index 53bd578d7e03d49ebae396b183fdf10140b3434d..32cf714857809b5ec591cd484c9e1c0671654529 100644 (file)
         _Pragma("GCC diagnostic push");                                 \
         _Pragma("GCC diagnostic ignored \"-Wnonnull\"")
 
         _Pragma("GCC diagnostic push");                                 \
         _Pragma("GCC diagnostic ignored \"-Wnonnull\"")
 
+#define DISABLE_WARNING_SHADOW                                          \
+        _Pragma("GCC diagnostic push");                                 \
+        _Pragma("GCC diagnostic ignored \"-Wshadow\"")
+
 #define REENABLE_WARNING                                                \
         _Pragma("GCC diagnostic pop")
 
 #define REENABLE_WARNING                                                \
         _Pragma("GCC diagnostic pop")