]> granicus.if.org Git - clang/commitdiff
When typo-correction an Objective-C superclass name, don't
authorDouglas Gregor <dgregor@apple.com>
Thu, 1 Dec 2011 15:37:53 +0000 (15:37 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 1 Dec 2011 15:37:53 +0000 (15:37 +0000)
typo-correct to ourselves.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145583 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/class-def-test-1.m

index 667a12fea4499e508797e04e8c004893d7cc5270..49fcfbf2f376bc7870e37fcf539d0df3bddfaf44 100644 (file)
@@ -417,10 +417,15 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
           DeclarationNameInfo(SuperName, SuperLoc), LookupOrdinaryName, TUScope,
           NULL, NULL, false, CTC_NoKeywords);
       if ((PrevDecl = Corrected.getCorrectionDeclAs<ObjCInterfaceDecl>())) {
-        Diag(SuperLoc, diag::err_undef_superclass_suggest)
-          << SuperName << ClassName << PrevDecl->getDeclName();
-        Diag(PrevDecl->getLocation(), diag::note_previous_decl)
-          << PrevDecl->getDeclName();
+        if (PrevDecl == IDecl) {
+          // Don't correct to the class we're defining.
+          PrevDecl = 0;
+        } else {
+          Diag(SuperLoc, diag::err_undef_superclass_suggest)
+            << SuperName << ClassName << PrevDecl->getDeclName();
+          Diag(PrevDecl->getLocation(), diag::note_previous_decl)
+            << PrevDecl->getDeclName();
+        }
       }
     }
 
index 95a259bd527bc22eea9b2313d6c7578560fd04a6..0d114b99fb6db016066f51223d52994235fce6c7 100644 (file)
@@ -30,4 +30,6 @@ typedef NSObject TD_NSObject;
 @interface XCElementUnit : TD_NSObject {}
 @end
 
-
+// Make sure we don't typo-correct to ourselves.
+@interface SomeClassSub : SomeClassSup // expected-error{{cannot find interface declaration for 'SomeClassSup', superclass of 'SomeClassSub'}}
+@end