summaryrefslogtreecommitdiff
path: root/tests/test-stdbool.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2022-10-24 22:25:29 +0200
committerJörg Frings-Fürst <debian@jff.email>2022-10-24 22:25:29 +0200
commit26112352a774737e1ce5580c93654a26c1e82b39 (patch)
treed64e2f5b6e7aa92fa9a8ffb8ae5df75310532714 /tests/test-stdbool.c
parentbe8efac78d067c138ad8dda03df4336e73f94887 (diff)
New upstream version 1.1upstream/1.1
Diffstat (limited to 'tests/test-stdbool.c')
-rw-r--r--tests/test-stdbool.c51
1 files changed, 24 insertions, 27 deletions
diff --git a/tests/test-stdbool.c b/tests/test-stdbool.c
index ecc3c66a..923a2cd3 100644
--- a/tests/test-stdbool.c
+++ b/tests/test-stdbool.c
@@ -1,9 +1,9 @@
-/* Test of <stdbool.h> substitute.
+/* Test bool.
Copyright (C) 2002-2007, 2009-2022 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
+ the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
@@ -33,37 +33,34 @@
#include <config.h>
-#include <stdbool.h>
-
-#ifndef bool
- "error: bool is not defined"
-#endif
-#ifndef false
- "error: false is not defined"
+#ifdef TEST_STDBOOL_H
+# include <stdbool.h>
#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 ((HAVE_C_BOOL || defined __cplusplus \
+ || HAVE_STDBOOL_H || 3 <= __GNUC__ || 4 <= __clang_major__) \
+ && !defined _MSC_VER)
+# 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 +70,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. */
{