Jelajahi Sumber

When typo-correction an Objective-C superclass name, don't
typo-correct to ourselves.


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

Douglas Gregor 13 tahun lalu
induk
melakukan
a38c4730fb
2 mengubah file dengan 12 tambahan dan 5 penghapusan
  1. 9 4
      lib/Sema/SemaDeclObjC.cpp
  2. 3 1
      test/SemaObjC/class-def-test-1.m

+ 9 - 4
lib/Sema/SemaDeclObjC.cpp

@@ -417,10 +417,15 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
           DeclarationNameInfo(SuperName, SuperLoc), LookupOrdinaryName, TUScope,
           DeclarationNameInfo(SuperName, SuperLoc), LookupOrdinaryName, TUScope,
           NULL, NULL, false, CTC_NoKeywords);
           NULL, NULL, false, CTC_NoKeywords);
       if ((PrevDecl = Corrected.getCorrectionDeclAs<ObjCInterfaceDecl>())) {
       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();
+        }
       }
       }
     }
     }
 
 

+ 3 - 1
test/SemaObjC/class-def-test-1.m

@@ -30,4 +30,6 @@ typedef NSObject TD_NSObject;
 @interface XCElementUnit : TD_NSObject {}
 @interface XCElementUnit : TD_NSObject {}
 @end
 @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