[cfe-commits] r154595 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Rewriter/objc-bool-literal-modern-1.mm test/SemaObjCXX/literals.mm
Fariborz Jahanian
fjahanian at apple.com
Thu Apr 12 10:49:18 PDT 2012
Author: fjahanian
Date: Thu Apr 12 12:49:18 2012
New Revision: 154595
URL: http://llvm.org/viewvc/llvm-project?rev=154595&view=rev
Log:
objective-c numeric literal: type of boolean is
that of typedef BOOL if found.
// rdar://11231426
Added:
cfe/trunk/test/Rewriter/objc-bool-literal-modern-1.mm
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaObjCXX/literals.mm
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=154595&r1=154594&r2=154595&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Apr 12 12:49:18 2012
@@ -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));
}
Added: cfe/trunk/test/Rewriter/objc-bool-literal-modern-1.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/objc-bool-literal-modern-1.mm?rev=154595&view=auto
==============================================================================
--- cfe/trunk/test/Rewriter/objc-bool-literal-modern-1.mm (added)
+++ cfe/trunk/test/Rewriter/objc-bool-literal-modern-1.mm Thu Apr 12 12:49:18 2012
@@ -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;
+ });
+}
Modified: cfe/trunk/test/SemaObjCXX/literals.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/literals.mm?rev=154595&r1=154594&r2=154595&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/literals.mm (original)
+++ cfe/trunk/test/SemaObjCXX/literals.mm Thu Apr 12 12:49:18 2012
@@ -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;
More information about the cfe-commits
mailing list