gh-91731: Don't define 'static_assert' in C++11 where is a keyword to avoid UB (GH-93700)

(cherry picked from commit 65ff27c7d3)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit is contained in:
Miss Islington (bot) 2022-06-16 07:50:15 -07:00 committed by GitHub
parent 0c49a09e67
commit 74561095d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -12,8 +12,10 @@
// static_assert is defined in glibc from version 2.16. Before it requires // static_assert is defined in glibc from version 2.16. Before it requires
// compiler support (gcc >= 4.6) and is called _Static_assert. // compiler support (gcc >= 4.6) and is called _Static_assert.
// In C++ 11 static_assert is a keyword, redefining is undefined behaviour.
#if (defined(__GLIBC__) \ #if (defined(__GLIBC__) \
&& (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 16)) \ && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 16)) \
&& !(defined(__cplusplus) && __cplusplus >= 201103L) \
&& !defined(static_assert)) && !defined(static_assert))
# define static_assert _Static_assert # define static_assert _Static_assert
#endif #endif

View File

@ -0,0 +1,3 @@
Avoid defining the ``static_assert`` when compiling with C++ 11, where this
is a keyword and redefining it can lead to undefined behavior. Patch by
Pablo Galindo