diff options
Diffstat (limited to 'lib/verify.h')
-rw-r--r-- | lib/verify.h | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/lib/verify.h b/lib/verify.h index 58172f3cb7f..d485a0283a9 100644 --- a/lib/verify.h +++ b/lib/verify.h @@ -23,11 +23,15 @@ /* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert (R, DIAGNOSTIC) works as per C11. This is supported by GCC 4.6.0 and later, in C - mode. + mode, and by clang (also in C++ mode). Define _GL_HAVE__STATIC_ASSERT1 to 1 if _Static_assert (R) works as - per C2X, and define _GL_HAVE_STATIC_ASSERT1 if static_assert (R) - works as per C++17. This is supported by GCC 9.1 and later. + per C2X. This is supported by GCC 9.1 and later, and by clang in + C++1z mode. + + Define _GL_HAVE_STATIC_ASSERT1 if static_assert (R) works as per + C++17. This is supported by GCC 9.1 and later, and by clang in + C++1z mode. Support compilers claiming conformance to the relevant standard, and also support GCC when not pedantic. If we were willing to slow @@ -35,7 +39,8 @@ since this affects only the quality of diagnostics, why bother? */ #ifndef __cplusplus # if (201112L <= __STDC_VERSION__ \ - || (!defined __STRICT_ANSI__ && 4 < __GNUC__ + (6 <= __GNUC_MINOR__))) + || (!defined __STRICT_ANSI__ \ + && (4 < __GNUC__ + (6 <= __GNUC_MINOR__) || 4 <= __clang_major__))) # define _GL_HAVE__STATIC_ASSERT 1 # endif # if (202000L <= __STDC_VERSION__ \ @@ -43,7 +48,15 @@ # define _GL_HAVE__STATIC_ASSERT1 1 # endif #else -# if 201703L <= __cplusplus || 9 <= __GNUC__ +# if 4 <= __clang_major__ +# define _GL_HAVE__STATIC_ASSERT 1 +# endif +# if 4 <= __clang_major__ && 201411 <= __cpp_static_assert +# define _GL_HAVE__STATIC_ASSERT1 1 +# endif +# if 201703L <= __cplusplus \ + || 9 <= __GNUC__ \ + || (4 <= __clang_major__ && 201411 <= __cpp_static_assert) # define _GL_HAVE_STATIC_ASSERT1 1 # endif #endif @@ -233,13 +246,6 @@ template <int w> /* @assert.h omit start@ */ -#if defined __has_builtin -/* <https://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions> */ -# define _GL_HAS_BUILTIN_ASSUME __has_builtin (__builtin_assume) -#else -# define _GL_HAS_BUILTIN_ASSUME 0 -#endif - #if 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__)) # define _GL_HAS_BUILTIN_TRAP 1 #elif defined __has_builtin @@ -299,11 +305,14 @@ template <int w> Although assuming R can help a compiler generate better code or diagnostics, performance can suffer if R uses hard-to-optimize - features such as function calls not inlined by the compiler. */ + features such as function calls not inlined by the compiler. + + Avoid Clang’s __builtin_assume, as clang 9.0.1 -Wassume can + generate a bogus diagnostic "the argument to '__builtin_assume' has + side effects that will be discarded" even when the argument has no + side effects. */ -#if _GL_HAS_BUILTIN_ASSUME -# define assume(R) __builtin_assume (R) -#elif _GL_HAS_BUILTIN_UNREACHABLE +#if _GL_HAS_BUILTIN_UNREACHABLE # define assume(R) ((R) ? (void) 0 : __builtin_unreachable ()) #elif 1200 <= _MSC_VER # define assume(R) __assume (R) |