[Mesa-dev] [PATCH] Avoid spurious GCC warnings in STATIC_ASSERT() macro.

Paul Berry stereotype441 at gmail.com
Tue Apr 2 15:16:31 PDT 2013


GCC 4.8 now warns about typedefs that are local to a scope and not
used anywhere within that scope.  This produces spurious warnings with
the STATIC_ASSERT() macro (which uses a typedef to provoke a compile
error in the event of an assertion failure).

This patch avoids the warning using the GCC __attribute__((unused))
syntax.
---
 src/mesa/main/compiler.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/mesa/main/compiler.h b/src/mesa/main/compiler.h
index 8b23665..ddeb61d 100644
--- a/src/mesa/main/compiler.h
+++ b/src/mesa/main/compiler.h
@@ -249,6 +249,12 @@ static INLINE GLuint CPU_TO_LE32(GLuint x)
 #endif
 
 
+#if (__GNUC__ >= 3)
+#define GCC_ATTRIBUTE_UNUSED __attribute__((unused))
+#else
+#define GCC_ATTRIBUTE_UNUSED
+#endif
+
 /**
  * Static (compile-time) assertion.
  * Basically, use COND to dimension an array.  If COND is false/zero the
@@ -256,7 +262,7 @@ static INLINE GLuint CPU_TO_LE32(GLuint x)
  */
 #define STATIC_ASSERT(COND) \
    do { \
-      typedef int static_assertion_failed[(!!(COND))*2-1]; \
+      typedef int static_assertion_failed[(!!(COND))*2-1] GCC_ATTRIBUTE_UNUSED; \
    } while (0)
 
 
-- 
1.8.2



More information about the mesa-dev mailing list