[cfe-commits] r115028 - in /cfe/trunk: lib/Headers/stdbool.h test/Headers/stdbool.cpp

Douglas Gregor dgregor at apple.com
Tue Sep 28 21:57:11 PDT 2010


Author: dgregor
Date: Tue Sep 28 23:57:11 2010
New Revision: 115028

URL: http://llvm.org/viewvc/llvm-project?rev=115028&view=rev
Log:
Define _Bool, bool, true, and false macros in <stdbool.h> when we're
in a GNU-compatible C++ dialect. Fixes <rdar://problem/8477819>.

Added:
    cfe/trunk/test/Headers/stdbool.cpp   (with props)
Modified:
    cfe/trunk/lib/Headers/stdbool.h

Modified: cfe/trunk/lib/Headers/stdbool.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/stdbool.h?rev=115028&r1=115027&r2=115028&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/stdbool.h (original)
+++ cfe/trunk/lib/Headers/stdbool.h Tue Sep 28 23:57:11 2010
@@ -26,11 +26,17 @@
 #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

Added: cfe/trunk/test/Headers/stdbool.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/stdbool.cpp?rev=115028&view=auto
==============================================================================
--- cfe/trunk/test/Headers/stdbool.cpp (added)
+++ cfe/trunk/test/Headers/stdbool.cpp Tue Sep 28 23:57:11 2010
@@ -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

Propchange: cfe/trunk/test/Headers/stdbool.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/Headers/stdbool.cpp
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cfe/trunk/test/Headers/stdbool.cpp
------------------------------------------------------------------------------
    svn:mime-type = text/plain





More information about the cfe-commits mailing list