diff options
-rw-r--r-- | meson.build | 2 | ||||
-rwxr-xr-x | scons/gallium.py | 1 | ||||
-rw-r--r-- | src/util/macros.h | 21 |
3 files changed, 18 insertions, 6 deletions
diff --git a/meson.build b/meson.build index 6118efc6dc1..a925746a654 100644 --- a/meson.build +++ b/meson.build @@ -1090,7 +1090,7 @@ else # Check for C and C++ arguments for MSVC compatibility. These are only used # in parts of the mesa code base that need to compile with MSVC, mainly # common code - foreach a : ['-Werror=pointer-arith', '-Werror=vla', '-Werror=gnu-empty-initializer'] + foreach a : ['-Werror=pointer-arith', '-Werror=gnu-empty-initializer'] if cc.has_argument(a) c_msvc_compat_args += a endif diff --git a/scons/gallium.py b/scons/gallium.py index e831912c761..03d11e440a1 100755 --- a/scons/gallium.py +++ b/scons/gallium.py @@ -86,7 +86,6 @@ def install_shared_library(env, sources, version = ()): def msvc2013_compat(env): if env['gcc']: env.Append(CCFLAGS = [ - '-Werror=vla', '-Werror=pointer-arith', ]) diff --git a/src/util/macros.h b/src/util/macros.h index 9b313c172ed..3483428bc5d 100644 --- a/src/util/macros.h +++ b/src/util/macros.h @@ -66,13 +66,26 @@ /** * Static (compile-time) assertion. - * Basically, use COND to dimension an array. If COND is false/zero the - * array size will be -1 and we'll get a compilation error. */ -#define STATIC_ASSERT(COND) \ - do { \ +#if defined(_MSC_VER) + /* MSVC doesn't like VLA's, but it also dislikes zero length arrays + * (which gcc is happy with), so we have to define STATIC_ASSERT() + * slightly differently. + */ +# define STATIC_ASSERT(COND) do { \ + (void) sizeof(char [(COND) != 0]); \ + } while (0) +#elif defined(__GNUC__) + /* This version of STATIC_ASSERT() relies on VLAs. If COND is + * false/zero, the array size will be -1 and we'll get a compile + * error + */ +# define STATIC_ASSERT(COND) do { \ (void) sizeof(char [1 - 2*!(COND)]); \ } while (0) +#else +# define STATIC_ASSERT(COND) do { } while (0) +#endif /** |