diff options
-rw-r--r-- | AST/ASTContext.cpp | 14 | ||||
-rw-r--r-- | test/Sema/objc-comptypes-1.m | 6 | ||||
-rw-r--r-- | test/Sema/objc-string.m | 7 |
3 files changed, 22 insertions, 5 deletions
diff --git a/AST/ASTContext.cpp b/AST/ASTContext.cpp index 531b348489..417c56570a 100644 --- a/AST/ASTContext.cpp +++ b/AST/ASTContext.cpp @@ -1235,7 +1235,19 @@ bool ASTContext::objcTypesAreCompatible(QualType lhs, QualType rhs) { } bool ASTContext::interfaceTypesAreCompatible(QualType lhs, QualType rhs) { - return true; // FIXME: IMPLEMENT. + if (lhs == rhs) + return true; + ObjcInterfaceType *lhsIT = cast<ObjcInterfaceType>(lhs.getTypePtr()); + ObjcInterfaceType *rhsIT = cast<ObjcInterfaceType>(rhs.getTypePtr()); + ObjcInterfaceDecl *rhsIDecl = rhsIT->getDecl(); + ObjcInterfaceDecl *lhsIDecl = lhsIT->getDecl(); + // rhs is derived from lhs it is OK; else it is not OK. + while (rhsIDecl != NULL) { + if (rhsIDecl == lhsIDecl) + return true; + rhsIDecl = rhsIDecl->getSuperClass(); + } + return false; } bool ASTContext::QualifiedInterfaceTypesAreCompatible(QualType lhs, diff --git a/test/Sema/objc-comptypes-1.m b/test/Sema/objc-comptypes-1.m index 246dfa1a41..c4b457ee68 100644 --- a/test/Sema/objc-comptypes-1.m +++ b/test/Sema/objc-comptypes-1.m @@ -33,6 +33,7 @@ int main() /* Assigning to a 'MyClass *' variable should always generate a warning, unless done from an 'id'. */ obj_c = obj; /* Ok */ + obj_c = obj_cp; // // expected-warning {{incompatible pointer types assigning 'MyOtherClass *' to 'MyClass *'}} obj_c = obj_C; // expected-warning {{incompatible pointer types assigning 'Class' to 'MyClass *'}} /* Assigning to an 'id<MyProtocol>' variable should generate a @@ -48,6 +49,7 @@ int main() a warning, unless done from an 'id' or an 'id<MyProtocol>' (since MyOtherClass implements MyProtocol). */ obj_cp = obj; /* Ok */ + obj_cp = obj_c; // expected-warning {{incompatible pointer types assigning 'MyClass *' to 'MyOtherClass *'}} obj_cp = obj_p; /* Ok */ obj_cp = obj_C; // expected-warning {{incompatible pointer types assigning 'Class' to 'MyOtherClass *'}} @@ -64,6 +66,10 @@ int main() /* Any comparison between 'MyClass *' and anything which is not an 'id' must generate a warning. */ if (obj_p == obj_c) foo() ; // expected-error {{invalid operands to binary expression ('id<MyProtocol>' and 'MyClass *')}} + + if (obj_c == obj_cp) foo() ; // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'MyOtherClass *')}} + if (obj_cp == obj_c) foo() ; // expected-warning {{comparison of distinct pointer types ('MyOtherClass *' and 'MyClass *')}} + if (obj_c == obj_C) foo() ; // expected-warning {{comparison of distinct pointer types ('MyClass *' and 'Class')}} if (obj_C == obj_c) foo() ; // expected-warning {{comparison of distinct pointer types ('Class' and 'MyClass *')}} diff --git a/test/Sema/objc-string.m b/test/Sema/objc-string.m index 4fe4394164..c73948292d 100644 --- a/test/Sema/objc-string.m +++ b/test/Sema/objc-string.m @@ -1,12 +1,11 @@ // RUN: clang %s -verify -fsyntax-only -@class NSString; @interface NSConstantString; @end -NSString *s = @"123"; // simple -NSString *t = @"123" @"456"; // concat -NSString *u = @"123" @ blah; // expected-error: {{unexpected token}} +NSConstantString *s = @"123"; // simple +NSConstantString *t = @"123" @"456"; // concat +NSConstantString *u = @"123" @ blah; // expected-error: {{unexpected token}} |