]> Savannah Git Hosting - gnulib.git/commitdiff
assert-h, verify: Fix compilation error with g++ (4.8.5) -std=gnu++11.
authorBruno Haible <bruno@clisp.org>
Thu, 30 May 2024 18:06:58 +0000 (20:06 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 31 May 2024 22:11:17 +0000 (00:11 +0200)
Reported by Harmen <harmen@stoppels.ch> at
<https://savannah.gnu.org/bugs/index.php?65811>.

* lib/verify.h (static_assert): In C++ mode with g++ < 6 and
-std=gnu++11, define in a way that supports also the 1-argument
invocations and the invocations inside C++ struct and class.

ChangeLog
lib/verify.h

index 011a35f9ba268501646879f78dc2c91fa88ada51..85fc1de073b54d0091a07dbf00513b0da3280327 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-05-30  Bruno Haible  <bruno@clisp.org>
+
+       assert-h, verify: Fix compilation error with g++ (4.8.5) -std=gnu++11.
+       Reported by Harmen <harmen@stoppels.ch> at
+       <https://savannah.gnu.org/bugs/index.php?65811>.
+       * lib/verify.h (static_assert): In C++ mode with g++ < 6 and
+       -std=gnu++11, define in a way that supports also the 1-argument
+       invocations and the invocations inside C++ struct and class.
+
 2024-05-31  Bruno Haible  <bruno@clisp.org>
 
        windows-once: Free allocated resources when done.
index e4af91517e6336814ad24f1c2d141b6c65cedc8c..21a9ae62fd40c41ca3fe6505412bd579a4b8f911 100644 (file)
@@ -1,6 +1,6 @@
 /* Compile-time assert-like macros.
 
-   Copyright (C) 2005-2006, 2009-2023 Free Software Foundation, Inc.
+   Copyright (C) 2005-2006, 2009-2024 Free Software Foundation, Inc.
 
    This file is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as
@@ -259,11 +259,22 @@ template <int w>
       && (!defined __cplusplus \
           || (__cpp_static_assert < 201411 \
               && __GNUG__ < 6 && __clang_major__ < 6 && _MSC_VER < 1910)))
-#  if defined __cplusplus && _MSC_VER >= 1900 && !defined __clang__
+#  if (defined __cplusplus && defined __GNUG__ && __GNUG__ < 6 \
+       && __cplusplus == 201103L && !defined __clang__)
+/* g++ >= 4.7, < 6 with option -std=c++11 or -std=gnu++11 supports the
+   two-arguments static_assert but not the one-argument static_assert, and
+   it does not support _Static_assert.
+   We have to play preprocessor tricks to distinguish the two cases.  */
+#   define _GL_SA1(a1) static_assert ((a1), "static assertion failed")
+#   define _GL_SA2 static_assert
+#   define _GL_SA3 static_assert
+#   define _GL_SA_PICK(x1,x2,x3,x4,...) x4
+#   define static_assert(...) _GL_SA_PICK(__VA_ARGS__,_GL_SA3,_GL_SA2,_GL_SA1) (__VA_ARGS__)
+#  elif defined __cplusplus && _MSC_VER >= 1900 && !defined __clang__
 /* MSVC 14 in C++ mode supports the two-arguments static_assert but not
    the one-argument static_assert, and it does not support _Static_assert.
    We have to play preprocessor tricks to distinguish the two cases.
-   Since the MSVC preprocessor is not ISO C compliant (see above),.
+   Since the MSVC preprocessor is not ISO C compliant (see above),
    the solution is specific to MSVC.  */
 #   define _GL_EXPAND(x) x
 #   define _GL_SA1(a1) static_assert ((a1), "static assertion failed")