summaryrefslogtreecommitdiff
path: root/doc/posix-headers/assert.texi
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 /doc/posix-headers/assert.texi
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 'doc/posix-headers/assert.texi')
-rw-r--r--doc/posix-headers/assert.texi21
1 files changed, 13 insertions, 8 deletions
diff --git a/doc/posix-headers/assert.texi b/doc/posix-headers/assert.texi
index 785a07aa98..fa99d3b880 100644
--- a/doc/posix-headers/assert.texi
+++ b/doc/posix-headers/assert.texi
@@ -5,29 +5,34 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/based
Gnulib module: assert-h
-See also the Gnulib module @code{assert}.
+See also the Gnulib modules @code{assert} and @code{verify}.
Portability problems fixed by Gnulib:
@itemize
@item
-The C11 and C++11 @code{static_assert}, and the C11
-@code{_Static_assert}, are not supported by many platforms.
-For example, GCC versions before 4.6.0 do not support @code{_Static_assert},
-and G++ versions through at least 4.6.0 do not support @code{static_assert}.
+On older platforms @code{static_assert} and @code{_Static_assert} do
+not allow the second string-literal argument to be omitted. For
+example, GCC versions before 9.1 do not support the single-argument
+@code{static_assert} that was standardized by C2X and C++17.
+@item
+Even-older platforms do not support @code{static_assert} or
+@code{_Static_assert} at all. For example, GCC versions before 4.6 do
+not support @code{_Static_assert}, and G++ versions before 4.3 do not
+support @code{static_assert}, which was standardized by C11 and C++11.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
@item
-C11 @code{_Static_assert} and C++11 @code{static_assert}
+C @code{_Static_assert} and C++ @code{static_assert}
are keywords that can be used without including @code{<assert.h>}.
The Gnulib substitutes are macros that require including @code{<assert.h>}.
@item
-The C11 @code{static_assert} and @code{_Static_assert} can also
+The C @code{static_assert} and @code{_Static_assert} can also
be used within a @code{struct} or @code{union} specifier, in place of
an ordinary declaration of a member of the struct or union. The
Gnulib substitute can be used only as an ordinary declaration.
@item
-In C99, @code{assert} can be applied to any scalar expression.
+In C99 and later, @code{assert} can be applied to any scalar expression.
In C89, the argument to @code{assert} is of type @code{int}.
@end itemize