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

Kenneth Graunke kenneth at whitecape.org
Wed Apr 3 12:34:53 PDT 2013


On 04/03/2013 12:22 PM, Paul Berry wrote:
> GCC 4.8 now warns about typedefs that are local to a scope and not
> used anywhere within that scope.  This produced spurious warnings with
> the STATIC_ASSERT() macro (which used a typedef to provoke a compile
> error in the event of an assertion failure).
>
> This patch switches to a simpler technique that avoids the warning.
>
> v2: Avoid GCC-specific syntax.  Also update p_compiler.h.
> ---
>   src/gallium/include/pipe/p_compiler.h | 2 +-
>   src/mesa/main/compiler.h              | 2 +-
>   2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/gallium/include/pipe/p_compiler.h b/src/gallium/include/pipe/p_compiler.h
> index a131969..78ec83c 100644
> --- a/src/gallium/include/pipe/p_compiler.h
> +++ b/src/gallium/include/pipe/p_compiler.h
> @@ -255,7 +255,7 @@ void _ReadWriteBarrier(void);
>    */
>   #define STATIC_ASSERT(COND) \
>      do { \
> -      typedef int static_assertion_failed[(!!(COND))*2-1]; \
> +      (void) sizeof(char [1 - 2*!(COND)]); \
>      } while (0)
>
>
> diff --git a/src/mesa/main/compiler.h b/src/mesa/main/compiler.h
> index 8b23665..8431534 100644
> --- a/src/mesa/main/compiler.h
> +++ b/src/mesa/main/compiler.h
> @@ -256,7 +256,7 @@ static INLINE GLuint CPU_TO_LE32(GLuint x)
>    */
>   #define STATIC_ASSERT(COND) \
>      do { \
> -      typedef int static_assertion_failed[(!!(COND))*2-1]; \
> +      (void) sizeof(char [1 - 2*!(COND)]); \
>      } while (0)

Yeah, I just upgraded yesterday and started seeing these.  thanks for 
fixing them, Paul.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>


More information about the mesa-dev mailing list