diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index 667a12fea449..49fcfbf2f376 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/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/clang/test/SemaObjC/class-def-test-1.m b/clang/test/SemaObjC/class-def-test-1.m index 95a259bd527b..0d114b99fb6d 100644 --- a/clang/test/SemaObjC/class-def-test-1.m +++ b/clang/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