summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2022-08-13 20:00:02 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2022-08-13 20:00:59 -0700
commitf960bc91cd325cee7e1262944ca6114bfd4d1c1f (patch)
treed51083bb7993c211ea45c33c353d9b8065b51697 /tests
parentaa46eb2a5344ea32a973cdc2bb7b9d81d146543f (diff)
downloadgnulib-f960bc91cd325cee7e1262944ca6114bfd4d1c1f.tar.gz
stdbool: port to C23
* m4/stdbool.m4 (AC_CHECK_HEADER_STDBOOL): Copy from bleeding-edge Autoconf. Don’t define if Autoconf 2.72 or later. * tests/test-stdbool.c (bool, false, true) (__bool_true_false_are_defined): Do not require these to be defined. C23 still requires __bool_true_false_are_defined but marks it as obsolescent, and it’s no longer worth testing. (WORKING_BOOL): New macro, which also tests __STDC_VERSION__. Use it in tests for working bool. Test for bool instead of for _Bool, which C23 says is obsolescent.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-stdbool.c41
1 files changed, 18 insertions, 23 deletions
diff --git a/tests/test-stdbool.c b/tests/test-stdbool.c
index 3574a9e72f..27fd16d010 100644
--- a/tests/test-stdbool.c
+++ b/tests/test-stdbool.c
@@ -35,35 +35,30 @@
#include <stdbool.h>
-#ifndef bool
- "error: bool is not defined"
-#endif
-#ifndef false
- "error: false is not defined"
-#endif
#if false
"error: false is not 0"
#endif
-#ifndef true
- "error: true is not defined"
-#endif
#if true != 1
"error: true is not 1"
#endif
-#ifndef __bool_true_false_are_defined
- "error: __bool_true_false_are_defined is not defined"
-#endif
/* Several tests cannot be guaranteed with gnulib's <stdbool.h>, at
least, not for all compilers and compiler options. */
-#if HAVE_STDBOOL_H || 3 <= __GNUC__ || 4 <= __clang_major__
-struct s { _Bool s: 1; _Bool t; } s;
+#if (202311 <= __STDC_VERSION__ || defined __cplusplus \
+ || HAVE_STDBOOL_H || 3 <= __GNUC__ || 4 <= __clang_major__)
+# define WORKING_BOOL 1
+#else
+# define WORKING_BOOL 0
+#endif
+
+#if WORKING_BOOL
+struct s { bool s: 1; bool t; } s;
#endif
char a[true == 1 ? 1 : -1];
char b[false == 0 ? 1 : -1];
char c[__bool_true_false_are_defined == 1 ? 1 : -1];
-#if HAVE_STDBOOL_H || 3 <= __GNUC__ || 4 <= __clang_major__ /* See above. */
+#if WORKING_BOOL
char d[(bool) 0.5 == true ? 1 : -1];
# ifdef ADDRESS_CHECK_OKAY /* Avoid gcc warning. */
/* C99 may plausibly be interpreted as not requiring support for a cast from
@@ -73,30 +68,30 @@ char d[(bool) 0.5 == true ? 1 : -1];
bool e = &s;
# endif
# endif
-char f[(_Bool) 0.0 == false ? 1 : -1];
+char f[(bool) 0.0 == false ? 1 : -1];
#endif
char g[true];
-char h[sizeof (_Bool)];
-#if HAVE_STDBOOL_H || 3 <= __GNUC__ || 4 <= __clang_major__ /* See above. */
+char h[sizeof (bool)];
+#if WORKING_BOOL
char i[sizeof s.t];
#endif
enum { j = false, k = true, l = false * true, m = true * 256 };
-_Bool n[m];
+bool n[m];
char o[sizeof n == m * sizeof n[0] ? 1 : -1];
-char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
+char p[-1 - (bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
/* Catch a bug in an HP-UX C compiler. See
https://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
https://lists.gnu.org/r/bug-coreutils/2005-11/msg00161.html
*/
-_Bool q = true;
-_Bool *pq = &q;
+bool q = true;
+bool *pq = &q;
int
main ()
{
int error = 0;
-#if HAVE_STDBOOL_H || 3 <= __GNUC_ || 4 <= __clang_major___ /* See above. */
+#if WORKING_BOOL
# ifdef ADDRESS_CHECK_OKAY /* Avoid gcc warning. */
/* A cast from a variable's address to bool is valid in expressions. */
{