summaryrefslogtreecommitdiff
path: root/m4/assert_h.m4
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2019-05-09 08:57:56 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2019-05-09 09:09:34 -0700
commit89a5b4b828b962361be83904b5914ec4bb3408ec (patch)
tree304f84c52ca8a1e948532e0f3377e08e235d8431 /m4/assert_h.m4
parentb8068cf09b6c78e35cef072efc7613049c11a632 (diff)
downloadgnulib-89a5b4b828b962361be83904b5914ec4bb3408ec.tar.gz
Support C2X and C++17 static_assert
C2X and C++17 finally added support for a simple, single-argument ‘static_assert’ that implements what the Gnulib ‘verify’ macro was doing back in 2005. Implement static_assert on older platforms. The only remaining advantage of ‘verify’ is a shorter name. * doc/posix-headers/assert.texi (assert.h): * doc/verify.texi (Compile-time Assertions): Modernize for C2X and C++17. * lib/verify.h (_GL_HAVE__STATIC_ASSERT1, _GL_HAVE_STATIC_ASSERT1): New macros. (_GL_HAVE__STATIC_ASSERT): Remove. (_GL_HAVE__STATIC_ASSERT): Rely more heavily on __STDC_VERSION__. (_GL_VERIFY_TRUE, _GL_VERIFY_TYPE): Remove 2nd arg, the diagnostic string. All callers changed. (_GL_VERIFY): Require 3 or more args, of which only the first 2 are used. All callers changed. (_Static_assert): Allow either 1 or 2 args, and define if !_GL_HAVE__STATIC_ASSERT1 instead of defining if !_GL_HAVE__STATIC_ASSERT. (static_assert): Define if !_GL_HAVE_STATIC_ASSERT1 instead of defining if !_GL_HAVE_STATIC_ASSERT. (verify_expr, verify): Don’t bother trying to copy the expression into the diagnostic, since 1-argument static_assert doesn’t. (verify): Prefer 1-argument _Static_assert if it works. * m4/assert_h.m4 (gl_ASSERT_H): Check for 1-argument static_assert.
Diffstat (limited to 'm4/assert_h.m4')
-rw-r--r--m4/assert_h.m42
1 files changed, 2 insertions, 0 deletions
diff --git a/m4/assert_h.m4 b/m4/assert_h.m4
index cf11bae6a8..ee278b2068 100644
--- a/m4/assert_h.m4
+++ b/m4/assert_h.m4
@@ -14,9 +14,11 @@ AC_DEFUN([gl_ASSERT_H],
[AC_LANG_PROGRAM(
[[#include <assert.h>
static_assert (2 + 2 == 4, "arithmetic doesn't work");
+ static_assert (2 + 2 == 4);
]],
[[
static_assert (sizeof (char) == 1, "sizeof doesn't work");
+ static_assert (sizeof (char) == 1);
]])],
[gl_cv_static_assert=yes],
[gl_cv_static_assert=no])])