From adfe905145f9425a3df3bb282195f651dffb99d7 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 6 Feb 2012 19:06:20 +0000 Subject: [PATCH] objc: fixes a problem in block type comparison involving enums with underlying type explicitly specified (feature which is on by default in objective-c). // rdar://10798770 llvm-svn: 149888 --- clang/lib/AST/ASTContext.cpp | 6 ++++-- clang/test/SemaObjC/block-type-safety.m | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 51cbc3c9d7b8..416045e2342e 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -5960,11 +5960,13 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS, // Compatibility is based on the underlying type, not the promotion // type. if (const EnumType* ETy = LHS->getAs()) { - if (ETy->getDecl()->getIntegerType() == RHSCan.getUnqualifiedType()) + QualType TINT = ETy->getDecl()->getIntegerType(); + if (!TINT.isNull() && hasSameType(TINT, RHSCan.getUnqualifiedType())) return RHS; } if (const EnumType* ETy = RHS->getAs()) { - if (ETy->getDecl()->getIntegerType() == LHSCan.getUnqualifiedType()) + QualType TINT = ETy->getDecl()->getIntegerType(); + if (!TINT.isNull() && hasSameType(TINT, LHSCan.getUnqualifiedType())) return LHS; } // allow block pointer type to match an 'id' type. diff --git a/clang/test/SemaObjC/block-type-safety.m b/clang/test/SemaObjC/block-type-safety.m index ebc6777f7fbb..bfb848e01cb6 100644 --- a/clang/test/SemaObjC/block-type-safety.m +++ b/clang/test/SemaObjC/block-type-safety.m @@ -138,3 +138,20 @@ int test5() { return 0; } +// rdar://10798770 +typedef int NSInteger; + +typedef enum : NSInteger {NSOrderedAscending = -1L, NSOrderedSame, NSOrderedDescending} NSComparisonResult; + +typedef NSComparisonResult (^NSComparator)(id obj1, id obj2); + +@interface radar10798770 +- (void)sortUsingComparator:(NSComparator)c; +@end + +void f() { + radar10798770 *f; + [f sortUsingComparator:^(id a, id b) { + return NSOrderedSame; + }]; +}