Re: [PROPOSED 2/2] assert-h: prefer to ‘verify’

2022-12-28 Thread Paul Eggert

On 9/14/22 04:35, Bruno Haible wrote:

-#  define _Static_assert(...) \
- _GL_VERIFY (__VA_ARGS__, "static assertion failed", -)
+#  define _Static_assert(R, ...) \
+ _GL_VERIFY ((R), "static assertion failed", -)


Unfortunately this doesn't conform to strict C99, which requires the 
updated _Static_assert to be called with at least two arguments. I 
discovered this while compiling bleeding-edge gzip on AIX and on 
Solaris. I worked around the problem by installing the attached patch, 
though since I don't use MSVC I'm not sure I got the new #if exactly right.


Also, does MSVC require the "(R)" to be parenthesized? I also noticed 
what would ordinarily be unnecessary parentheses later on, in the 
MSVC-specific '#   define _GL_SA1(a1) static_assert ((a1), "static 
assertion failed")'. Ordinarily I like to leave those parentheses out 
but if MSVC needs them obviously we should keep them.
From 14a7b0ce5462c90ce86d97bf952185ec2500d341 Mon Sep 17 00:00:00 2001
From: Paul Eggert 
Date: Wed, 28 Dec 2022 14:15:43 -0800
Subject: [PATCH] assert-h: port static_assert to strict C99
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lib/verify.h (_GL_VERIFY): Port MSVC hack back to C99.
Problem found when testing bleeding-edge gzip on IBM XL C for AIX,
V12.1 (5765-J02, 5725-C72), which complained ‘"malloca.c", line
42.56: 1506-041 (E) The invocation of macro _Static_assert
contains fewer arguments than are required by the macro
definition.’  This diagnostic is valid because C99 requires
that if you #define _Static_assert(R, ...) you must call
_Static_assert with at least two arguments.  I found a similar
problem with Sun C 5.9 SunOS_sparc Patch 124867-12 2009/11/22.
---
 ChangeLog| 13 +
 lib/verify.h | 16 +++-
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index be0fb22078..49f88777eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2022-12-28  Paul Eggert  
+
+	assert-h: port static_assert to strict C99
+	* lib/verify.h (_GL_VERIFY): Port MSVC hack back to C99.
+	Problem found when testing bleeding-edge gzip on IBM XL C for AIX,
+	V12.1 (5765-J02, 5725-C72), which complained ‘"malloca.c", line
+	42.56: 1506-041 (E) The invocation of macro _Static_assert
+	contains fewer arguments than are required by the macro
+	definition.’  This diagnostic is valid because C99 requires
+	that if you #define _Static_assert(R, ...) you must call
+	_Static_assert with at least two arguments.  I found a similar
+	problem with Sun C 5.9 SunOS_sparc Patch 124867-12 2009/11/22.
+
 2022-12-27  Paul Eggert  
 
 	file-has-acl: fix recently-introduced NFSv4 bug
diff --git a/lib/verify.h b/lib/verify.h
index 5225a8e616..cb635a9fc2 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -223,8 +223,15 @@ template 
 /* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h.  */
 #ifdef _GL_STATIC_ASSERT_H
 # if !defined _GL_HAVE__STATIC_ASSERT1 && !defined _Static_assert
-#  define _Static_assert(R, ...) \
- _GL_VERIFY ((R), "static assertion failed", -)
+#  if !defined _MSC_VER || defined __clang__
+#   define _Static_assert(...) \
+  _GL_VERIFY (__VA_ARGS__, "static assertion failed", -)
+#  else
+/* Work around MSVC preprocessor incompatibility with ISO C; see
+   .  */
+#   define _Static_assert(R, ...) \
+  _GL_VERIFY ((R), "static assertion failed", -)
+#  endif
 # endif
 # if (!defined static_assert \
   && __STDC_VERSION__ < 202311 \
@@ -235,9 +242,8 @@ template 
 /* 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 (cf.
-   ), the solution is specific
-   to MSVC.  */
+   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")
 #   define _GL_SA2 static_assert
-- 
2.25.1



Re: [PROPOSED 2/2] assert-h: prefer to ‘verify’

2022-09-14 Thread Bruno Haible
Paul Eggert wrote:
> Where it’s easy, prefer ‘static_assert’ to ‘verify’,

In a build of GNU gettext, with clang and the MSVC header files, I get errors
starting like this:

/bin/sh ./libtool  --tag=CXX   --mode=compile /home/bruno/msvc/compile clang-cl 
-ferror-limit=0 -DIN_LIBASPRINTF -DHAVE_CONFIG_H -D__USE_MINGW_ANSI_STDIO=0 -I. 
-I../../../gettext-runtime/libasprintf  -Ignulib-lib 
-I../../../gettext-runtime/libasprintf/gnulib-lib 
-D_WIN32_WINNT=_WIN32_WINNT_WIN7 -I/usr/local/msvcclang64/include -Wall 
-Wno-extra-semi-stmt -Wno-unused-function -Wno-inconsistent-dllimport 
-Wno-reserved-id-macro -Wno-undef -Wno-missing-field-initializers 
-Wno-unused-parameter -Wno-gnu-include-next -Wno-implicit-int-conversion 
-Wno-sign-compare -Wno-sign-conversion -Wno-comma -Wno-unused-macros 
-Wno-nonportable-system-include-path -Wno-format-nonliteral 
-Wno-deprecated-declarations -Wno-tautological-unsigned-zero-compare 
-Wno-used-but-marked-unused -Wno-parentheses-equality  -MD -O2 -c -o 
autosprintf.lo ../../../gettext-runtime/libasprintf/autosprintf.cc
libtool: compile:  /home/bruno/msvc/compile clang-cl -ferror-limit=0 
-DIN_LIBASPRINTF -DHAVE_CONFIG_H -D__USE_MINGW_ANSI_STDIO=0 -I. 
-I../../../gettext-runtime/libasprintf -Ignulib-lib 
-I../../../gettext-runtime/libasprintf/gnulib-lib 
-D_WIN32_WINNT=_WIN32_WINNT_WIN7 -I/usr/local/msvcclang64/include -Wall 
-Wno-extra-semi-stmt -Wno-unused-function -Wno-inconsistent-dllimport 
-Wno-reserved-id-macro -Wno-undef -Wno-missing-field-initializers 
-Wno-unused-parameter -Wno-gnu-include-next -Wno-implicit-int-conversion 
-Wno-sign-compare -Wno-sign-conversion -Wno-comma -Wno-unused-macros 
-Wno-nonportable-system-include-path -Wno-format-nonliteral 
-Wno-deprecated-declarations -Wno-tautological-unsigned-zero-compare 
-Wno-used-but-marked-unused -Wno-parentheses-equality -MD -O2 -c 
../../../gettext-runtime/libasprintf/autosprintf.cc -o autosprintf.obj
In file included from ../../../gettext-runtime/libasprintf/autosprintf.cc:18:
In file included from .\config.h:1098:
gnulib-lib\assert.h(239,43): warning: variadic macros are incompatible with 
C++98 [-Wc++98-compat-pedantic]
# define _GL_STATIC_ASSERT(R, DIAGNOSTIC, ...) static_assert (R, DIAGNOSTIC)
  ^
gnulib-lib\assert.h(254,29): warning: variadic macros are incompatible with 
C++98 [-Wc++98-compat-pedantic]
#  define _Static_assert(R, ...) \
^
gnulib-lib\assert.h(274,12): warning: keyword is hidden by macro definition 
[-Wkeyword-macro]
#   define static_assert _Static_assert /* C11 requires this #define. */
   ^
In file included from ../../../gettext-runtime/libasprintf/autosprintf.cc:21:
In file included from .\autosprintf.h:35:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 
14.0\VC\include\string:6:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 
14.0\VC\include\istream:6:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 
14.0\VC\include\ostream:6:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 
14.0\VC\include\ios:6:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 
14.0\VC\include\xlocnum:6:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 
14.0\VC\include\climits:5:
In file included from C:\Program Files (x86)\Microsoft Visual Studio 
14.0\VC\include\yvals.h:7:
C:\Program Files (x86)\Microsoft Visual Studio 
14.0\VC\include\xkeycheck.h(250,5): error: The C++ Standard Library forbids 
macroizing keywords. Enable warning C4005 to find the forbidden macro.
   #error The C++ Standard Library forbids macroizing keywords. Enable warning 
C4005 to find the forbidden macro.
^

This patch fixes it. Similarly to what we did with g++ 6.


2022-09-14  Bruno Haible  

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 .

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 
 # 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.
   

Re: [PROPOSED 2/2] assert-h: prefer to ‘verify’

2022-09-14 Thread Bruno Haible
> > Where it’s easy, prefer ‘static_assert’ to ‘verify’,
> 
> Compiling a current GNU gettext with MSVC 14, I get this compilation error:

I got this working, by using preprocessor tricks, inspired by
  
  
  
  


2022-09-14  Bruno Haible  

verify: Avoid syntax error due to static_assert with MSVC 14 in C++.
* lib/verify.h (static_assert): For MSVC in C++ mode, use a definition
that supports both the two-arguments and the one-argument syntax.

diff --git a/lib/verify.h b/lib/verify.h
index a0d597f3d4..0f5f0edc86 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -229,7 +229,22 @@ template 
 # if (!defined static_assert \
   && __STDC_VERSION__ < 202311 \
   && __cpp_static_assert < 201411 && __GNUG__ < 6)
-#  define static_assert _Static_assert /* C11 requires this #define.  */
+#  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.
+   We have to play preprocessor tricks to distinguish the two cases.
+   Since the MSVC preprocessor is not ISO C compliant (cf.
+   ), the solution is specific
+   to MSVC.  */
+#   define _GL_EXPAND(x) x
+#   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_EXPAND(_GL_SA_PICK(__VA_ARGS__,_GL_SA3,_GL_SA2,_GL_SA1)) (__VA_ARGS__)
+#  else
+#   define static_assert _Static_assert /* C11 requires this #define. */
+#  endif
 # endif
 #endif
 






Re: [PROPOSED 2/2] assert-h: prefer to ‘verify’

2022-09-14 Thread Bruno Haible
Paul Eggert wrote:
> Where it’s easy, prefer ‘static_assert’ to ‘verify’,

Compiling a current GNU gettext with MSVC 14, I get this compilation error:

libtool: compile:  /home/bruno/msvc/compile cl -nologo -DIN_LIBASPRINTF 
-DHAVE_CONFIG_H -D__USE_MINGW_ANSI_STDIO=0 -I. 
-I../../../gettext-runtime/libasprintf -Ignulib-lib 
-I../../../gettext-runtime/libasprintf/gnulib-lib 
-D_WIN32_WINNT=_WIN32_WINNT_WIN7 -I/usr/local/msvc64/include -MD -c 
../../../gettext-runtime/libasprintf/autosprintf.cc -o autosprintf.obj
autosprintf.cc
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xstddef(376): 
error C2720: 'std::hash<_Kty>::_gl_static_assert_function3': 'extern' 
storage-class specifier illegal on members
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xstddef(378): 
note: see reference to class template instantiation 'std::hash<_Kty>' being 
compiled
C:\Program Files (x86)\Microsoft Visual Studio 
14.0\VC\include\type_traits(744): error C2720: 
'std::_Change_sign<_Ty>::_gl_static_assert_function4': 'extern' storage-class 
specifier illegal on members
C:\Program Files (x86)\Microsoft Visual Studio 
14.0\VC\include\type_traits(777): note: see reference to class template 
instantiation 'std::_Change_sign<_Ty>' being compiled
C:\Program Files (x86)\Microsoft Visual Studio 
14.0\VC\include\type_traits(1193): error C2720: 
'std::integer_sequence<_Ty,_Vals...>::_gl_static_assert_function5': 'extern' 
storage-class specifier illegal on members
C:\Program Files (x86)\Microsoft Visual Studio 
14.0\VC\include\type_traits(1203): note: see reference to class template 
instantiation 'std::integer_sequence<_Ty,_Vals...>' being compiled
C:\Program Files (x86)\Microsoft Visual Studio 
14.0\VC\include\type_traits(1502): error C2720: 
'std::result_of<_Fty>::_gl_static_assert_function7': 'extern' storage-class 
specifier illegal on members
C:\Program Files (x86)\Microsoft Visual Studio 
14.0\VC\include\type_traits(1505): note: see reference to class template 
instantiation 'std::result_of<_Fty>' being compiled
C:\Program Files (x86)\Microsoft Visual Studio 
14.0\VC\include\type_traits(1580): error C2720: 
'std::reference_wrapper<_Ty>::_gl_static_assert_function8': 'extern' 
storage-class specifier illegal on members
C:\Program Files (x86)\Microsoft Visual Studio 
14.0\VC\include\type_traits(1612): note: see reference to class template 
instantiation 'std::reference_wrapper<_Ty>' being compiled
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\utility(423): 
error C2720: 
'std::tuple_element<_Idx,std::array<_Ty,_Size>>::_gl_static_assert_function9': 
'extern' storage-class specifier illegal on members
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\utility(426): 
note: see reference to class template instantiation 
'std::tuple_element<_Idx,std::array<_Ty,_Size>>' being compiled
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\utility(445): 
error C2059: syntax error: ')'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\utility(447): 
note: see reference to class template instantiation 
'std::tuple_element<_Index,std::tuple<>>' being compiled
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\utility(445): 
error C2947: expecting '>' to terminate template-argument-list, found '>'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\utility(445): 
error C2976: 'std::integral_constant': too few template arguments
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xtr1common(23): 
note: see declaration of 'std::integral_constant'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\utility(447): 
error C2143: syntax error: missing ';' before '}'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\utility(447): 
fatal error C1004: unexpected end-of-file found
make[4]: *** [Makefile:1412: autosprintf.lo] Error 1

The situation with this compiler (in C++ mode) is:
  - It supports 'static_assert' with 2 arguments.
  - It does not support 'static_assert' with 1 argument.
  - Its header files make use of the 'static_assert' with 2 arguments,
for example:

template
struct tuple_element<_Index, tuple<> >
{   // enforce bounds checking
static_assert(_Always_false >::value,
"tuple index out of bounds");
};

Thus, our existing definition of static_assert via _Static_assert an _GL_VERIFY
does not work, because 'extern' is not allowed inside a struct/class definition.

This attempted patch

diff --git a/lib/verify.h b/lib/verify.h
index a0d597f3d4..608c9bda20 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -229,7 +229,13 @@ template 
 # if (!defined static_assert \
   && __STDC_VERSION__ < 202311 \
   && __cpp_static_assert < 201411 && __GNUG__ < 6)
-#  define static_assert _Static_assert /* C11 requires this #define.  */
+#  if defined __cplusplus && _MSC_VER >= 1900
+/* MSVC 14 in C++ mode supports the 2-arguments static_assert but not 

Re: [PROPOSED 2/2] assert-h: prefer to ‘verify’

2022-09-14 Thread Bruno Haible
Paul Eggert wrote:
> Where it’s easy, prefer ‘static_assert’ to ‘verify’,

On MSVC 14, in C mode, I get compilation errors:

...\gnulib-tests\test-assert.c(27): warning C4116: unnamed type definition in 
parentheses
...\gnulib-tests\test-assert.c(27): error C2057: expected constant expression
...\gnulib-tests\test-assert.c(27): error C2149: 
'_gl_static_assert_error_if_negative': named bit field cannot have zero width
...\gnulib-tests\test-assert.c(43): warning C4116: unnamed type definition in 
parentheses
...\gnulib-tests\test-assert.c(43): error C2057: expected constant expression
...\gnulib-tests\test-assert.c(43): error C2149: 
'_gl_static_assert_error_if_negative': named bit field cannot have zero width
...\gnulib-tests\test-assert.c(55): warning C4116: unnamed type definition in 
parentheses
...\gnulib-tests\test-assert.c(55): error C2057: expected constant expression
...\gnulib-tests\test-assert.c(55): error C2149: 
'_gl_static_assert_error_if_negative': named bit field cannot have zero width
...\gnulib-tests\test-assert.c(67): warning C4116: unnamed type definition in 
parentheses
...\gnulib-tests\test-assert.c(67): error C2057: expected constant expression
...\gnulib-tests\test-assert.c(67): error C2149: 
'_gl_static_assert_error_if_negative': named bit field cannot have zero width
make[3]: *** [Makefile:7324: test-assert.obj] Error 2

How come? These lines from the test program

  static_assert (2 + 2 == 4, "arithmetic does not work");
  static_assert (2 + 2 == 4);
  static_assert (sizeof (char) == 1, "sizeof does not work");
  static_assert (sizeof (char) == 1);

macroexpand to

  extern int (*_gl_static_assert_function2 (void)) [(!!sizeof (struct { 
unsigned int _gl_static_assert_error_if_negative: (2 + 2 == 4, "arithmetic does 
not work") ? 1 : -1; }))];
  extern int (*_gl_static_assert_function3 (void)) [(!!sizeof (struct { 
unsigned int _gl_static_assert_error_if_negative: (2 + 2 == 4) ? 1 : -1; }))];
  extern int (*_gl_static_assert_function4 (void)) [(!!sizeof (struct { 
unsigned int _gl_static_assert_error_if_negative: (sizeof (char) == 1, "sizeof 
does not work") ? 1 : -1; }))];
  extern int (*_gl_static_assert_function5 (void)) [(!!sizeof (struct { 
unsigned int _gl_static_assert_error_if_negative: (sizeof (char) == 1) ? 1 : 
-1; }))];

which obviously is nonsense, as the value of a comma expression is the last
part, not the first part.

This patch fixes it.


2022-09-14  Bruno Haible  

verify: Avoid syntax error due to static_assert with MSVC 14.
* lib/verify.h (_Static_assert): Pass only the first argument to
_GL_VERIFY.

diff --git a/lib/verify.h b/lib/verify.h
index 154a5b76bf..a0d597f3d4 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -223,8 +223,8 @@ template 
 /* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h.  */
 #ifdef _GL_STATIC_ASSERT_H
 # if !defined _GL_HAVE__STATIC_ASSERT1 && !defined _Static_assert
-#  define _Static_assert(...) \
- _GL_VERIFY (__VA_ARGS__, "static assertion failed", -)
+#  define _Static_assert(R, ...) \
+ _GL_VERIFY ((R), "static assertion failed", -)
 # endif
 # if (!defined static_assert \
   && __STDC_VERSION__ < 202311 \






Re: [PROPOSED 2/2] assert-h: prefer to ‘verify’

2022-09-14 Thread Bruno Haible
Paul Eggert wrote:
> >   # if (!defined static_assert \
> > -  && __STDC_VERSION__ < 202311 && __cpp_static_assert < 201411)
> > +  && __STDC_VERSION__ < 202311 \
> > +  && __cpp_static_assert < 201411 && __GNUG__ < 6)
> >   #  define static_assert _Static_assert /* C11 requires this #define.  */
> >   # endif
> 
> Thanks for the fix. Should I also install the attached patch, for 
> consistency?

Yes, please. Since the only purpose of the
 #include 
 #undef/**/assert
here is to get 'static_assert' working, and it works already in g++ ≥ 6,
the patch is correct.

Bruno






Re: [PROPOSED 2/2] assert-h: prefer to ‘verify’

2022-09-13 Thread Paul Eggert

On 9/13/22 20:05, Bruno Haible wrote:

  # if (!defined static_assert \
-  && __STDC_VERSION__ < 202311 && __cpp_static_assert < 201411)
+  && __STDC_VERSION__ < 202311 \
+  && __cpp_static_assert < 201411 && __GNUG__ < 6)
  #  define static_assert _Static_assert /* C11 requires this #define.  */
  # endif


Thanks for the fix. Should I also install the attached patch, for 
consistency?
From e993a048cf8c58755da7c3b358cadf2f598bbff3 Mon Sep 17 00:00:00 2001
From: Paul Eggert 
Date: Tue, 13 Sep 2022 23:01:53 -0500
Subject: [PATCH] verify: treat GNU C++ 6 like recent C++

* lib/verify.h (_GL_VERIFY):
* m4/assert_h.m4 (gl_ASSERT_H):
If we check __cpp_static_assert < 200410, also check __GNUG__ < 6,
for consistency with the previous change.
---
 ChangeLog  | 7 +++
 m4/assert_h.m4 | 3 ++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 81183fa619..2e04ffd8d1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2022-09-13  Paul Eggert  
+
+	verify: treat GNU C++ 6 like recent C++
+	* m4/assert_h.m4 (gl_ASSERT_H):
+	If we check __cpp_static_assert < 201411, also check __GNUG__ < 6,
+	for consistency with the previous change.
+
 2022-09-13  Bruno Haible  
 
 	verify: Avoid syntax error due to static_assert with GNU C++ 6.x.
diff --git a/m4/assert_h.m4 b/m4/assert_h.m4
index 36b3c78c91..ec756a970b 100644
--- a/m4/assert_h.m4
+++ b/m4/assert_h.m4
@@ -47,7 +47,8 @@ AC_DEFUN([gl_ASSERT_H],
   dnl including assert.h.  Break the #undef apart with a comment
   dnl so that 'configure' does not comment it out.
   AH_VERBATIM([zzstatic_assert],
-[#if !defined HAVE_C_STATIC_ASSERT && __cpp_static_assert < 201411
+[#if (!defined HAVE_C_STATIC_ASSERT \
+ && __cpp_static_assert < 201411 && __GNUG__ < 6)
  #include 
  #undef/**/assert
 #endif])
-- 
2.37.2



Re: [PROPOSED 2/2] assert-h: prefer to ‘verify’

2022-09-13 Thread Bruno Haible
Paul Eggert wrote:
> Where it’s easy, prefer ‘static_assert’ to ‘verify’,

Compiling a current GNU gettext with these patches on Cygwin and mingw
I get a compilation error:

/bin/sh ./libtool  --tag=CXX   --mode=compile x86_64-pc-cygwin-g++ 
-DIN_LIBASPRINTF -DHAVE_CONFIG_H -D__USE_MINGW_ANSI_STDIO=0 -I. 
-I../../../gettext-runtime/libasprintf  -Ignulib-lib 
-I../../../gettext-runtime/libasprintf/gnulib-lib -I/usr/local/cygwin64/include 
-Wall  -g -O2 -c -o autosprintf.lo 
../../../gettext-runtime/libasprintf/autosprintf.cc
libtool: compile:  x86_64-pc-cygwin-g++ -DIN_LIBASPRINTF -DHAVE_CONFIG_H 
-D__USE_MINGW_ANSI_STDIO=0 -I. -I../../../gettext-runtime/libasprintf 
-Ignulib-lib -I../../../gettext-runtime/libasprintf/gnulib-lib 
-I/usr/local/cygwin64/include -Wall -g -O2 -c 
../../../gettext-runtime/libasprintf/autosprintf.cc -o autosprintf.o
In file included from ./config.h:1097:0,
 from ../../../gettext-runtime/libasprintf/autosprintf.cc:18:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/type_traits:1105:7: error: 
expected identifier before 'sizeof'
   static_assert(sizeof...(_Args) > 1,
   ^
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/type_traits:1105:7: error: 
expected ',' or '...' before 'sizeof'
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/type_traits:2093:7: error: 
expected identifier before 'sizeof'
   static_assert(sizeof...(_Types) != 0, "At least one type is required");
   ^
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/type_traits:2093:7: error: 
expected ',' or '...' before 'sizeof'
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/ptr_traits.h:114:7: error: 
expected identifier before '!' token
   static_assert(!is_same::value,
   ^
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/ptr_traits.h:114:7: error: 
expected ',' or '...' before '!' token
In file included from /usr/include/features.h:12:0,
 from gnulib-lib/wchar.h:66,
 from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/cwchar:44,
 from 
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/postypes.h:40,
 from 
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/bits/char_traits.h:40,
 from /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/string:40,
 from ./autosprintf.h:35,
 from ../../../gettext-runtime/libasprintf/autosprintf.cc:21:
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/utility:309:7: error: '_Num' is 
not a type
   static_assert( _Num >= 0,
   ^
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/include/c++/utility:309:7: error: expected 
',' or '...' before '>=' token
   static_assert( _Num >= 0,
   ^
make[6]: *** [Makefile:1412: autosprintf.lo] Error 1

This patch fixes it.


2022-09-13  Bruno Haible  

verify: Avoid syntax error due to static_assert with GNU C++ 6.x.
* lib/verify.h (static_assert): Don't define in GNU C++ 6 or newer.

diff --git a/lib/verify.h b/lib/verify.h
index 0066d211b2..154a5b76bf 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -227,7 +227,8 @@ template 
  _GL_VERIFY (__VA_ARGS__, "static assertion failed", -)
 # endif
 # if (!defined static_assert \
-  && __STDC_VERSION__ < 202311 && __cpp_static_assert < 201411)
+  && __STDC_VERSION__ < 202311 \
+  && __cpp_static_assert < 201411 && __GNUG__ < 6)
 #  define static_assert _Static_assert /* C11 requires this #define.  */
 # endif
 #endif






[PROPOSED 2/2] assert-h: prefer to ‘verify’

2022-09-12 Thread Paul Eggert
Where it’s easy, prefer ‘static_assert’ to ‘verify’,
as this simplifies the source by removing the need to
include verify.h.  Keep using ‘verify’ if verify.h
is used for other reasons, or if code is shared with glibc.
* lib/alignalloc.c, lib/argmatch.h, lib/c32is-impl.h:
* lib/c32snrtombs.c, lib/c32srtombs.c, lib/exclude.c:
* lib/filevercmp.c, lib/fma.c, lib/i-ring.h, lib/ino-map.c:
* lib/localeinfo.c, lib/malloca.c, lib/mbrtoc32.c, lib/mbrtowc.c:
* lib/mbsinit.c, lib/mbsnrtoc32s.c, lib/mbsrtoc32s.c:
* lib/nanosleep.c, lib/parse-datetime.y, lib/pipe2.c:
* lib/rawmemchr.c, lib/relocwrapper.c, lib/sleep.c:
* lib/stat-w32.c, lib/strerror.c, lib/strtoimax.c:
* lib/utimecmp.c, lib/vasnprintf.c, tests/test-alignof.c:
* tests/test-intprops.c, tests/test-libgmp.c:
* tests/test-limits-h.c, tests/test-locale.c:
* tests/test-pthread.c, tests/test-round2.c:
* tests/test-stdalign.c, tests/test-stddef.c, tests/test-stdio.c:
* tests/test-stdlib.c, tests/test-string.c, tests/test-sys_stat.c:
* tests/test-time.c, tests/test-uchar.c, tests/test-unistd.c:
* tests/test-wchar.c:
Prefer static_assert to verify, and stop including verify.h.
* lib/stat.c: Don’t include verify.h (this include was unnecessary).
* modules/alignalloc, modules/alignof-tests, modules/argmatch:
* modules/c-vasnprintf, modules/c32isalnum, modules/c32isalpha:
* modules/c32isblank, modules/c32iscntrl, modules/c32isdigit:
* modules/c32isgraph, modules/c32islower, modules/c32isprint:
* modules/c32ispunct, modules/c32isspace, modules/c32isupper:
* modules/c32isxdigit, modules/c32snrtombs, modules/c32srtombs:
* modules/exclude, modules/filevercmp, modules/fma, modules/fmaf:
* modules/fmal, modules/fstat, modules/i-ring, modules/ino-map:
* modules/intprops-tests, modules/libgmp-tests:
* modules/limits-h-tests, modules/locale-tests, modules/malloca:
* modules/mbrtoc32, modules/mbrtowc, modules/mbsinit:
* modules/mbsnrtoc32s, modules/mbsrtoc32s, modules/nanosleep:
* modules/parse-datetime, modules/pipe2, modules/pthread-h-tests:
* modules/rawmemchr, modules/relocatable-prog-wrapper:
* modules/round-tests, modules/roundf-tests, modules/sleep:
* modules/stat, modules/stdalign-tests, modules/stdckdint-tests:
* modules/stddef-tests, modules/stdio-tests, modules/stdlib-tests:
* modules/strerror, modules/string-tests, modules/strtoimax:
* modules/strtoumax, modules/sys_stat-tests, modules/time-tests:
* modules/uchar-tests, modules/unistd-tests:
* modules/unistdio/u16-u16-vasnprintf:
* modules/unistdio/u16-vasnprintf:
* modules/unistdio/u32-u32-vasnprintf:
* modules/unistdio/u32-vasnprintf:
* modules/unistdio/u8-u8-vasnprintf:
* modules/unistdio/u8-vasnprintf, modules/unistdio/ulc-vasnprintf:
* modules/utimecmp, modules/vasnprintf, modules/wchar-tests:
Depend on assert-h, not verify.
---
 ChangeLog   |  52 ++
 lib/alignalloc.c|   5 +-
 lib/argmatch.h  |   4 +-
 lib/c32is-impl.h|   3 +-
 lib/c32snrtombs.c   |   4 +-
 lib/c32srtombs.c|   4 +-
 lib/exclude.c   |   9 +-
 lib/filevercmp.c|   3 +-
 lib/fma.c   |   5 +-
 lib/i-ring.h|   3 +-
 lib/ino-map.c   |   3 +-
 lib/localeinfo.c|   8 +-
 lib/malloca.c   |   3 +-
 lib/mbrtoc32.c  |   3 +-
 lib/mbrtowc.c   |   3 +-
 lib/mbsinit.c   |   3 +-
 lib/mbsnrtoc32s.c   |   4 +-
 lib/mbsrtoc32s.c|   4 +-
 lib/nanosleep.c |   3 +-
 lib/parse-datetime.y|   9 +-
 lib/pipe2.c |   3 +-
 lib/rawmemchr.c |   3 +-
 lib/relocwrapper.c  |   3 +-
 lib/sleep.c |   4 +-
 lib/stat-w32.c  |   3 +-
 lib/stat.c  |   1 -
 lib/strerror.c  |   3 +-
 lib/strtoimax.c |   6 +-
 lib/utimecmp.c  |   3 +-
 lib/vasnprintf.c|  11 +-
 modules/alignalloc  |   2 +-
 modules/alignof-tests   |   3 +-
 modules/argmatch|   2 +-
 modules/c-vasnprintf|   2 +-
 modules/c32isalnum  |   2 +-
 modules/c32isalpha  |   2 +-
 modules/c32isblank  |   2 +-
 modules/c32iscntrl  |   2 +-
 modules/c32isdigit  |   2 +-
 modules/c32isgraph  |   2 +-
 modules/c32islower  |   2 +-
 modules/c32isprint  |   2 +-
 modules/c32ispunct  |   2 +-
 modules/c32isspace  |   2 +-
 modules/c32isupper  |   2 +-
 modules/c32isxdigit |   2 +-
 modules/c32snrtombs |   2 +-
 modules/c32srtombs  |   2 +-