summaryrefslogtreecommitdiff
path: root/doc/posix-headers/assert.texi
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2022-09-13 17:29:35 -0500
committerPaul Eggert <eggert@cs.ucla.edu>2022-09-13 17:52:20 -0500
commitc504bec035e90efceb212c538efc986ef3db7f7a (patch)
tree8cd4cf21835acc5e918a00560c6f12f2666045d7 /doc/posix-headers/assert.texi
parentc34d1933871b62037d45957bfc50184884dfe3a7 (diff)
downloadgnulib-c504bec035e90efceb212c538efc986ef3db7f7a.tar.gz
assert-h: static_assert is a keyword in C23
* m4/assert_h.m4 (gl_ASSERT_H): Also test for static_assert keyword a la C23, and define HAVE_C_STATIC_ASSERT if so. If not, arrange for config.h to #define static_assert by including <assert.h>, and then do "#undef assert" so that the assert macro still needs an explicit include. This should be safe even on very old hosts, as assert.h has been re-includable for decades. * tests/tests-assert.c: New test. * modules/assert-h-tests (Files, Makefile.am): Add it.
Diffstat (limited to 'doc/posix-headers/assert.texi')
-rw-r--r--doc/posix-headers/assert.texi37
1 files changed, 23 insertions, 14 deletions
diff --git a/doc/posix-headers/assert.texi b/doc/posix-headers/assert.texi
index 3392a1691a..f3d50533f9 100644
--- a/doc/posix-headers/assert.texi
+++ b/doc/posix-headers/assert.texi
@@ -10,28 +10,37 @@ See also the Gnulib modules @code{assert} and @code{verify}.
Portability problems fixed by Gnulib:
@itemize
@item
-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.
+On older C platforms @code{<assert.h>} must be included before using
+@code{static_assert}. For example, GCC versions before 13 do not
+support the @code{static_assert} keyword that was standardized by C23.
@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.
+On older platforms @code{static_assert} does 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 C23 and C++17.
+@item
+Even-older platforms do not support @code{static_assert} at all.
+For example, GCC versions before 4.6 and G++ versions before 4.3
+do not support the two-argument form, which was standardized
+by C11 and C++11.
+@item
+Older C platforms might not support the obsolescent
+@code{_Static_assert} keyword or macro.
+This portability problem should not matter with code using this
+module, as such code should use @code{static_assert} instead.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
@item
-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 C @code{static_assert} and @code{_Static_assert} can also
+A @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.
+Gnulib substitute can be used only as an ordinary declaration
+in code intended to be portable to C99 or earlier.
+@item
+In C23 and C++11 and later, @code{static_assert} is a keyword.
+In C11 and C17 it is a macro. Any Gnulib substitute is also a macro.
@item
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}.