From: Bruno Haible Date: Sun, 5 Feb 2023 10:19:28 +0000 (+0100) Subject: assert-h, verify: Fix compilation error in C++ mode with MSVC 14. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=3471a5b6acc09c47a4b9566dfde7e6a76be77aa6;p=gnulib.git assert-h, verify: Fix compilation error in C++ mode with MSVC 14. * lib/verify.h (static_assert): Define _ALLOW_KEYWORD_MACROS. * tests/test-assert-h-c++.cc: Strengthen test. * tests/test-assert-h-c++2.cc: Likewise. --- diff --git a/ChangeLog b/ChangeLog index eea8ce0dc2..07e8b0870a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2023-02-05 Bruno Haible + + assert-h, verify: Fix compilation error in C++ mode with MSVC 14. + * lib/verify.h (static_assert): Define _ALLOW_KEYWORD_MACROS. + * tests/test-assert-h-c++.cc: Strengthen test. + * tests/test-assert-h-c++2.cc: Likewise. + 2023-02-04 Bruno Haible assert-h, verify: Fix conflict with standard C++ header files on macOS. diff --git a/lib/verify.h b/lib/verify.h index e4a8278e03..ec0a41eb9c 100644 --- a/lib/verify.h +++ b/lib/verify.h @@ -264,6 +264,8 @@ template # define _GL_SA3 static_assert # define _GL_SA_PICK(x1,x2,x3,x4,...) x4 # define static_assert(...) _GL_EXPAND(_GL_SA_PICK(__VA_ARGS__,_GL_SA3,_GL_SA2,_GL_SA1)) (__VA_ARGS__) +/* Avoid "fatal error C1189: #error: The C++ Standard Library forbids macroizing keywords." */ +# define _ALLOW_KEYWORD_MACROS 1 # else # define static_assert _Static_assert /* C11 requires this #define. */ # endif diff --git a/tests/test-assert-h-c++.cc b/tests/test-assert-h-c++.cc index 6b76565633..7da8b377fd 100644 --- a/tests/test-assert-h-c++.cc +++ b/tests/test-assert-h-c++.cc @@ -26,6 +26,9 @@ #include +static_assert (2 + 2 == 4, "arithmetic does not work"); +static_assert (2 + 2 == 4); + int main () { diff --git a/tests/test-assert-h-c++2.cc b/tests/test-assert-h-c++2.cc index ffd7c8cf92..8808886202 100644 --- a/tests/test-assert-h-c++2.cc +++ b/tests/test-assert-h-c++2.cc @@ -22,3 +22,7 @@ /* Check against conflicts between and other C++ header files. */ #include #include + + +static_assert (2 + 2 == 4, "arithmetic does not work"); +static_assert (2 + 2 == 4);