From a38c4730fb016abc20a5479540b65ff3992095ab Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Thu, 1 Dec 2011 15:37:53 +0000 Subject: [PATCH] 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 --- lib/Sema/SemaDeclObjC.cpp | 13 +++++++++---- test/SemaObjC/class-def-test-1.m | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 667a12fea4..49fcfbf2f3 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -417,10 +417,15 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, DeclarationNameInfo(SuperName, SuperLoc), LookupOrdinaryName, TUScope, NULL, NULL, false, CTC_NoKeywords); if ((PrevDecl = Corrected.getCorrectionDeclAs())) { - 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(); + } } } diff --git a/test/SemaObjC/class-def-test-1.m b/test/SemaObjC/class-def-test-1.m index 95a259bd52..0d114b99fb 100644 --- a/test/SemaObjC/class-def-test-1.m +++ b/test/SemaObjC/class-def-test-1.m @@ -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 -- 2.50.1