Support C++11 static_assert

https://bugs.webkit.org/show_bug.cgi?id=113308

Reviewed by Alexey Proskuryakov.

Use the C++11 static_assert for COMPILE_ASSERT when it is available. Note that
even when compiling with C++11 support, static_assert will not always be available
since Assertions.h may also be used outside of C++.

C11 _Static_assert is enabled for GCC when it has C11 support (gcc>=4.7 -std=c11).

* wtf/Assertions.h:
* wtf/Compiler.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@146993 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9501cbc6
2013-03-27 Allan Sandfeld Jensen <allan.jensen@digia.com>
Support C++11 static_assert
https://bugs.webkit.org/show_bug.cgi?id=113308
Reviewed by Alexey Proskuryakov.
Use the C++11 static_assert for COMPILE_ASSERT when it is available. Note that
even when compiling with C++11 support, static_assert will not always be available
since Assertions.h may also be used outside of C++.
C11 _Static_assert is enabled for GCC when it has C11 support (gcc>=4.7 -std=c11).
* wtf/Assertions.h:
* wtf/Compiler.h:
2013-03-25 Oliver Hunt <oliver@apple.com>
RefCountedArray needs a size based constructor
......
......@@ -345,7 +345,10 @@ while (0)
/* COMPILE_ASSERT */
#ifndef COMPILE_ASSERT
#if COMPILER_SUPPORTS(C_STATIC_ASSERT)
/* Unlike static_assert below, this also works in plain C code. */
#define COMPILE_ASSERT(exp, name) _Static_assert((exp), #name)
#elif COMPILER_SUPPORTS(CXX_STATIC_ASSERT)
#define COMPILE_ASSERT(exp, name) static_assert((exp), #name)
#else
#define COMPILE_ASSERT(exp, name) typedef int dummy##name [(exp) ? 1 : -1]
#endif
......
......@@ -60,6 +60,7 @@
#define WTF_COMPILER_SUPPORTS_CXX_EXPLICIT_CONVERSIONS __has_feature(cxx_explicit_conversions)
#define WTF_COMPILER_SUPPORTS_BLOCKS __has_feature(blocks)
#define WTF_COMPILER_SUPPORTS_C_STATIC_ASSERT __has_extension(c_static_assert)
#define WTF_COMPILER_SUPPORTS_CXX_STATIC_ASSERT __has_extension(cxx_static_assert)
#define WTF_COMPILER_SUPPORTS_CXX_OVERRIDE_CONTROL __has_extension(cxx_override_control)
#define WTF_COMPILER_SUPPORTS_HAS_TRIVIAL_DESTRUCTOR __has_extension(has_trivial_destructor)
#define WTF_COMPILER_SUPPORTS_CXX_STRONG_ENUMS __has_extension(cxx_strong_enums)
......@@ -122,9 +123,15 @@
/* Specific compiler features */
#if COMPILER(GCC) && !COMPILER(CLANG)
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
/* C11 support */
#define WTF_COMPILER_SUPPORTS_C_STATIC_ASSERT 1
#endif
#if defined(__GXX_EXPERIMENTAL_CXX0X__) || (defined(__cplusplus) && __cplusplus >= 201103L)
/* C++11 support */
#if GCC_VERSION_AT_LEAST(4, 3, 0)
#define WTF_COMPILER_SUPPORTS_CXX_RVALUE_REFERENCES 1
#define WTF_COMPILER_SUPPORTS_CXX_STATIC_ASSERT 1
#define WTF_COMPILER_SUPPORTS_CXX_VARIADIC_TEMPLATES 1
#endif
#if GCC_VERSION_AT_LEAST(4, 4, 0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment