objective-c numeric literal: type of boolean is
that of typedef BOOL if found.
// rdar://11231426
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154595 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 1711f35..7748b8c 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -11259,6 +11259,18 @@
Sema::ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind) {
assert((Kind == tok::kw___objc_yes || Kind == tok::kw___objc_no) &&
"Unknown Objective-C Boolean value!");
+ QualType ObjCBoolLiteralQT = Context.ObjCBuiltinBoolTy;
+ // signed char is the default type for boolean literals. Use 'BOOL'
+ // instead, if BOOL typedef is visible in its scope instead.
+ Decl *TD =
+ LookupSingleName(TUScope, &Context.Idents.get("BOOL"),
+ SourceLocation(), LookupOrdinaryName);
+ if (TypeDecl *BoolTD = dyn_cast_or_null<TypeDecl>(TD)) {
+ QualType QT = QualType(BoolTD->getTypeForDecl(), 0);
+ if (!QT.isNull())
+ ObjCBoolLiteralQT = QT;
+ }
+
return Owned(new (Context) ObjCBoolLiteralExpr(Kind == tok::kw___objc_yes,
- Context.ObjCBuiltinBoolTy, OpLoc));
+ ObjCBoolLiteralQT, OpLoc));
}
diff --git a/test/Rewriter/objc-bool-literal-modern-1.mm b/test/Rewriter/objc-bool-literal-modern-1.mm
new file mode 100644
index 0000000..7825172
--- /dev/null
+++ b/test/Rewriter/objc-bool-literal-modern-1.mm
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"__declspec(X)=" %t-rw.cpp
+// rdar://11231426
+
+typedef bool BOOL;
+
+BOOL yes() {
+ return __objc_yes;
+}
+
+BOOL no() {
+ return __objc_no;
+}
+
+BOOL which (int flag) {
+ return flag ? yes() : no();
+}
+
+int main() {
+ which (__objc_yes);
+ which (__objc_no);
+ return __objc_yes;
+}
+
+void y(BOOL (^foo)());
+
+void x() {
+ y(^{
+ return __objc_yes;
+ });
+}
diff --git a/test/SemaObjCXX/literals.mm b/test/SemaObjCXX/literals.mm
index 1f6782a..eed6765 100644
--- a/test/SemaObjCXX/literals.mm
+++ b/test/SemaObjCXX/literals.mm
@@ -1,6 +1,15 @@
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x -fblocks %s
-typedef unsigned char BOOL;
+// rdar://11231426
+typedef bool BOOL;
+
+void y(BOOL (^foo)());
+
+void x() {
+ y(^{
+ return __objc_yes;
+ });
+}
@protocol NSCopying
- copy;