From d6f25832c0a02500602e44153e265e10a1d67ce4 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 14 Sep 2022 22:21:47 +0200
Subject: [PATCH] verify: Avoid syntax error due to static_assert with clang in
 C++ mode.

* lib/verify.h (static_assert): Don't define in clang C++ 6 or newer.
* m4/assert_h.m4 (gl_ASSERT_H): If we don't need to define static_assert
with clang in C++ mode, don't include <assert.h>.
---
 ChangeLog      | 7 +++++++
 lib/verify.h   | 4 +++-
 m4/assert_h.m4 | 4 +++-
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 199b088200..37d3ff7aa2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2022-09-14  Bruno Haible  <bruno@clisp.org>
+
+	verify: Avoid syntax error due to static_assert with clang in C++ mode.
+	* lib/verify.h (static_assert): Don't define in clang C++ 6 or newer.
+	* m4/assert_h.m4 (gl_ASSERT_H): If we don't need to define static_assert
+	with clang in C++ mode, don't include <assert.h>.
+
 2022-09-14  Paul Eggert  <eggert@cs.ucla.edu>
 
 	assert-h: work around include confusion
diff --git a/lib/verify.h b/lib/verify.h
index 0f5f0edc86..99af802993 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -228,7 +228,9 @@ template <int w>
 # endif
 # if (!defined static_assert \
       && __STDC_VERSION__ < 202311 \
-      && __cpp_static_assert < 201411 && __GNUG__ < 6)
+      && (!defined __cplusplus \
+          || (__cpp_static_assert < 201411 \
+              && __GNUG__ < 6 && __clang_major__ < 6)))
 #  if 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.
diff --git a/m4/assert_h.m4 b/m4/assert_h.m4
index 43937869ec..d61572113c 100644
--- a/m4/assert_h.m4
+++ b/m4/assert_h.m4
@@ -48,7 +48,9 @@ AC_DEFUN([gl_ASSERT_H],
   dnl so that 'configure' does not comment it out.
   AH_VERBATIM([zzstatic_assert],
 [#if (!defined HAVE_C_STATIC_ASSERT && !defined assert \
-     && __cpp_static_assert < 201411 && __GNUG__ < 6)
+     && (!defined __cplusplus \
+         || (__cpp_static_assert < 201411 \
+             && __GNUG__ < 6 && __clang_major__ < 6)))
  #include <assert.h>
  #undef/**/assert
 #endif])
-- 
2.39.5