Building a testdir on FreeBSD 11, I get this compilation error:

c++ -DHAVE_CONFIG_H -DEXEEXT=\"\" -DEXEEXT=\"\" -I. -I../../gltests -I..  
-DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I../../gltests -I.. 
-I../../gltests/.. -I../gllib -I../../gltests/../gllib -I/home/bruno/include 
-Wall -D_THREAD_SAFE  -Wno-error -g -O2 -MT test-assert-h-c++.o -MD -MP -MF 
$depbase.Tpo -c -o test-assert-h-c++.o ../../gltests/test-assert-h-c++.cc &&\
mv -f $depbase.Tpo $depbase.Po
../../gltests/test-assert-h-c++.cc:30:26: error: too few arguments provided to 
function-like macro invocation
static_assert (2 + 2 == 4);
                         ^
/usr/include/c++/v1/__config:631:9: note: macro 'static_assert' defined here
#define static_assert(__b, __m) \
        ^
../../gltests/test-assert-h-c++.cc:30:1: error: C++ requires a type specifier 
for all declarations
static_assert (2 + 2 == 4);
^
2 errors generated.
gmake[4]: *** [Makefile:28200: test-assert-h-c++.o] Error 1


c++ is clang version 3.8.0.

This patch fixes it.


2024-12-28  Bruno Haible  <br...@clisp.org>

        assert-h, verify: Make static_assert work in C++ mode on FreeBSD 11.
        * lib/verify.h (static_assert): Override when using old versions of
        clang++.

diff --git a/lib/verify.h b/lib/verify.h
index 49a73c0508..c4b6d50384 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -255,6 +255,11 @@ template <int w>
 #  endif
 # endif
 /* Define static_assert if needed.  */
+# if defined __cplusplus && defined __clang__ && __clang_major__ < 9
+/* clang++ before commit 5c739665a8721228cf6143fd4ef95870a59f55ae had a
+   two-arguments static_assert but not the one-argument static_assert.  */
+#  undef static_assert
+# endif
 # if (!defined static_assert \
       && __STDC_VERSION__ < 202311 \
       && (!defined __cplusplus \




Reply via email to