]> granicus.if.org Git - clang/commitdiff
Define _Bool, bool, true, and false macros in <stdbool.h> when we're
authorDouglas Gregor <dgregor@apple.com>
Wed, 29 Sep 2010 04:57:11 +0000 (04:57 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 29 Sep 2010 04:57:11 +0000 (04:57 +0000)
in a GNU-compatible C++ dialect. Fixes <rdar://problem/8477819>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@115028 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Headers/stdbool.h
test/Headers/stdbool.cpp [new file with mode: 0644]

index e44a1f9a979f5e7d95944dd650be3d2b8ddce960..0467893f3403f10f99fa83e998a313c6ab356b2a 100644 (file)
 #ifndef __STDBOOL_H
 #define __STDBOOL_H
 
-/* Don't define bool, true, and false in C++ */
+/* Don't define bool, true, and false in C++, except as a GNU extension. */
 #ifndef __cplusplus
 #define bool _Bool
 #define true 1
 #define false 0
+#elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
+/* Define _Bool, bool, false, true as a GNU extension. */
+#define _Bool bool
+#define bool  bool
+#define false false
+#define true  true
 #endif
 
 #define __bool_true_false_are_defined 1
diff --git a/test/Headers/stdbool.cpp b/test/Headers/stdbool.cpp
new file mode 100644 (file)
index 0000000..a252cca
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -E -dM %s | FileCheck --check-prefix=CHECK-GNU-COMPAT %s
+// RUN: %clang_cc1 -std=c++98 -E -dM %s | FileCheck --check-prefix=CHECK-CONFORMING %s
+#include <stdbool.h>
+#define zzz
+
+// CHECK-GNU-COMPAT: #define _Bool bool
+// CHECK-GNU-COMPAT: #define bool bool
+// CHECK-GNU-COMPAT: #define false false
+// CHECK-GNU-COMPAT: #define true true
+
+// CHECK-CONFORMING-NOT: #define _Bool
+// CHECK-CONFORMING: #define __CHAR_BIT__
+// CHECK-CONFORMING-NOT: #define false false
+// CHECK-CONFORMING: #define zzz