objective-c numeric literal: type of boolean is

that of typedef BOOL if found.
// rdar://11231426

llvm-svn: 154595
This commit is contained in:
Fariborz Jahanian 2012-04-12 17:49:18 +00:00
parent 6f3e5ad704
commit 30c3de97a9
3 changed files with 54 additions and 2 deletions

View File

@ -11259,6 +11259,18 @@ ExprResult
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));
}

View File

@ -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;
});
}

View File

@ -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;