r192594 - Do not use typo correction that is unaccessible.
Serge Pavlov
sepavloff at gmail.com
Mon Oct 14 07:05:49 PDT 2013
Author: sepavloff
Date: Mon Oct 14 09:05:48 2013
New Revision: 192594
URL: http://llvm.org/viewvc/llvm-project?rev=192594&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp
cfe/trunk/test/SemaObjC/bad-property-synthesis-crash.m
cfe/trunk/test/SemaObjC/error-outof-scope-property-use.m
Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=192594&r1=192593&r2=192594&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Mon Oct 14 09:05:48 2013
@@ -4167,8 +4167,15 @@ TypoCorrection Sema::CorrectTypo(const D
// 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.
Modified: cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp?rev=192594&r1=192593&r2=192594&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp (original)
+++ cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp Mon Oct 14 09:05:48 2013
@@ -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<class F>
+ 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<int> Q(0); // expected-note {{in instantiation of member function}}
+ }
+}
Modified: cfe/trunk/test/SemaObjC/bad-property-synthesis-crash.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/bad-property-synthesis-crash.m?rev=192594&r1=192593&r2=192594&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/bad-property-synthesis-crash.m (original)
+++ cfe/trunk/test/SemaObjC/bad-property-synthesis-crash.m Mon Oct 14 09:05:48 2013
@@ -13,7 +13,7 @@
__what; // expected-error {{use of undeclared identifier}} \
// expected-warning {{expression result unused}}
}
- at synthesize what; // expected-note 2 {{'what' declared here}}
+ at synthesize what; // expected-note {{'what' declared here}}
@end
@implementation Bar // expected-warning {{cannot find interface declaration for}}
Modified: cfe/trunk/test/SemaObjC/error-outof-scope-property-use.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/error-outof-scope-property-use.m?rev=192594&r1=192593&r2=192594&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/error-outof-scope-property-use.m (original)
+++ cfe/trunk/test/SemaObjC/error-outof-scope-property-use.m Mon Oct 14 09:05:48 2013
@@ -6,7 +6,7 @@
@interface LaunchdJobs
- at property (nonatomic,retain) NSMutableDictionary *uuids_jobs; // expected-note 2 {{'_uuids_jobs' declared here}}
+ at property (nonatomic,retain) NSMutableDictionary *uuids_jobs; // expected-note {{'_uuids_jobs' declared here}}
@end
More information about the cfe-commits
mailing list