From 81e34b1c137ffaa9b9c7d488744bdaa0cee8e845 Mon Sep 17 00:00:00 2001 From: Serge Pavlov Date: Mon, 14 Oct 2013 14:05:48 +0000 Subject: [PATCH] Do not use typo correction that is unaccessible. This patch fixes PR17019. When doing typo correction, Sema::CorrectTypo uses correction already seen for the same typo. This causes problems if that correction is from another scope and cannot be accessed in the current. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192594 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaLookup.cpp | 11 +++++++++-- test/SemaCXX/typo-correction-pt2.cpp | 17 +++++++++++++++++ test/SemaObjC/bad-property-synthesis-crash.m | 2 +- test/SemaObjC/error-outof-scope-property-use.m | 2 +- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 2b80b97728..6ffb787768 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -4167,8 +4167,15 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, // keyword case, we'll end up adding the keyword below. if (Cached->second) { if (!Cached->second.isKeyword() && - isCandidateViable(CCC, Cached->second)) - Consumer.addCorrection(Cached->second); + isCandidateViable(CCC, Cached->second)) { + // Do not use correction that is unaccessible in the given scope. + NamedDecl* CorrectionDecl = Cached->second.getCorrectionDecl(); + DeclarationNameInfo NameInfo(CorrectionDecl->getDeclName(), + CorrectionDecl->getLocation()); + LookupResult R(*this, NameInfo, LookupOrdinaryName); + if (LookupName(R, S)) + Consumer.addCorrection(Cached->second); + } } else { // Only honor no-correction cache hits when a callback that will validate // correction candidates is not being used. diff --git a/test/SemaCXX/typo-correction-pt2.cpp b/test/SemaCXX/typo-correction-pt2.cpp index f360649ccc..d22a8e92e0 100644 --- a/test/SemaCXX/typo-correction-pt2.cpp +++ b/test/SemaCXX/typo-correction-pt2.cpp @@ -151,3 +151,20 @@ struct S { void f() { my_menber = 1; } // expected-error {{use of undeclared identifier 'my_menber'; did you mean 'my_member'?}} }; } + +namespace PR17019 { + template + struct evil { + evil(F de) { // expected-note {{'de' declared here}} + de_; // expected-error {{use of undeclared identifier 'de_'; did you mean 'de'?}} \ + // expected-warning {{expression result unused}} + } + ~evil() { + de_->bar() // expected-error {{use of undeclared identifier 'de_'}} + } + }; + + void meow() { + evil Q(0); // expected-note {{in instantiation of member function}} + } +} diff --git a/test/SemaObjC/bad-property-synthesis-crash.m b/test/SemaObjC/bad-property-synthesis-crash.m index ea4e0045dc..94c680489d 100644 --- a/test/SemaObjC/bad-property-synthesis-crash.m +++ b/test/SemaObjC/bad-property-synthesis-crash.m @@ -13,7 +13,7 @@ __what; // expected-error {{use of undeclared identifier}} \ // expected-warning {{expression result unused}} } -@synthesize what; // expected-note 2 {{'what' declared here}} +@synthesize what; // expected-note {{'what' declared here}} @end @implementation Bar // expected-warning {{cannot find interface declaration for}} diff --git a/test/SemaObjC/error-outof-scope-property-use.m b/test/SemaObjC/error-outof-scope-property-use.m index 8767dc0b85..c480e2df0b 100644 --- a/test/SemaObjC/error-outof-scope-property-use.m +++ b/test/SemaObjC/error-outof-scope-property-use.m @@ -6,7 +6,7 @@ @interface LaunchdJobs -@property (nonatomic,retain) NSMutableDictionary *uuids_jobs; // expected-note 2 {{'_uuids_jobs' declared here}} +@property (nonatomic,retain) NSMutableDictionary *uuids_jobs; // expected-note {{'_uuids_jobs' declared here}} @end -- 2.40.0