From: Bruno Haible Date: Thu, 30 May 2024 18:06:58 +0000 (+0200) Subject: assert-h, verify: Fix compilation error with g++ (4.8.5) -std=gnu++11. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=0770dc765c6f2fc66ae655f8b0228778e7121283;p=gnulib.git assert-h, verify: Fix compilation error with g++ (4.8.5) -std=gnu++11. Reported by Harmen at . * 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. --- diff --git a/ChangeLog b/ChangeLog index 011a35f9ba..85fc1de073 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2024-05-30 Bruno Haible + + assert-h, verify: Fix compilation error with g++ (4.8.5) -std=gnu++11. + Reported by Harmen at + . + * 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 windows-once: Free allocated resources when done. diff --git a/lib/verify.h b/lib/verify.h index e4af91517e..21a9ae62fd 100644 --- a/lib/verify.h +++ b/lib/verify.h @@ -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 && (!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")