<div dir="ltr">On Mon, Oct 14, 2013 at 7:05 AM, Serge Pavlov <span dir="ltr"><<a href="mailto:sepavloff@gmail.com" target="_blank">sepavloff@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: sepavloff<br>
Date: Mon Oct 14 09:05:48 2013<br>
New Revision: 192594<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=192594&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=192594&view=rev</a><br>
Log:<br>
Do not use typo correction that is unaccessible.<br>
This patch fixes PR17019. When doing typo correction, Sema::CorrectTypo uses<br>
correction already seen for the same typo. This causes problems if that<br>
correction is from another scope and cannot be accessed in the current.<br>
<br>
Modified:<br>
    cfe/trunk/lib/Sema/SemaLookup.cpp<br>
    cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp<br>
    cfe/trunk/test/SemaObjC/bad-property-synthesis-crash.m<br>
    cfe/trunk/test/SemaObjC/error-outof-scope-property-use.m<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaLookup.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=192594&r1=192593&r2=192594&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=192594&r1=192593&r2=192594&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Mon Oct 14 09:05:48 2013<br>
@@ -4167,8 +4167,15 @@ TypoCorrection Sema::CorrectTypo(const D<br>
       // keyword case, we'll end up adding the keyword below.<br>
       if (Cached->second) {<br>
         if (!Cached->second.isKeyword() &&<br>
-            isCandidateViable(CCC, Cached->second))<br>
-          Consumer.addCorrection(Cached->second);<br>
+            isCandidateViable(CCC, Cached->second)) {<br>
+          // Do not use correction that is unaccessible in the given scope. </blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+          NamedDecl* CorrectionDecl = Cached->second.getCorrectionDecl();<br></blockquote><div><br></div><div>* on the right, please.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+          DeclarationNameInfo NameInfo(CorrectionDecl->getDeclName(),<br>
+                                       CorrectionDecl->getLocation());<br>
+          LookupResult R(*this, NameInfo, LookupOrdinaryName);<br>
+          if (LookupName(R, S))<br>
+            Consumer.addCorrection(Cached->second);<br>
+        }<br>
       } else {<br>
         // Only honor no-correction cache hits when a callback that will validate<br>
         // correction candidates is not being used.<br>
<br>
Modified: cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp?rev=192594&r1=192593&r2=192594&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp?rev=192594&r1=192593&r2=192594&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/typo-correction-pt2.cpp Mon Oct 14 09:05:48 2013<br>
@@ -151,3 +151,20 @@ struct S {<br>
   void f() { my_menber = 1; }  // expected-error {{use of undeclared identifier 'my_menber'; did you mean 'my_member'?}}<br>
 };<br>
 }<br>
+<br>
+namespace PR17019 {<br>
+  template<class F><br>
+  struct evil {<br>
+    evil(F de) {  // expected-note {{'de' declared here}}<br>
+      de_;  // expected-error {{use of undeclared identifier 'de_'; did you mean 'de'?}} \<br>
+            // expected-warning {{expression result unused}}<br>
+    }<br>
+    ~evil() {<br>
+      de_->bar()  // expected-error {{use of undeclared identifier 'de_'}}<br>
+    }<br>
+  };<br>
+<br>
+  void meow() {<br>
+    evil<int> Q(0); // expected-note {{in instantiation of member function}}<br>
+  }<br>
+}<br>
<br>
Modified: cfe/trunk/test/SemaObjC/bad-property-synthesis-crash.m<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/bad-property-synthesis-crash.m?rev=192594&r1=192593&r2=192594&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/bad-property-synthesis-crash.m?rev=192594&r1=192593&r2=192594&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/SemaObjC/bad-property-synthesis-crash.m (original)<br>
+++ cfe/trunk/test/SemaObjC/bad-property-synthesis-crash.m Mon Oct 14 09:05:48 2013<br>
@@ -13,7 +13,7 @@<br>
   __what; // expected-error {{use of undeclared identifier}} \<br>
           // expected-warning {{expression result unused}}<br>
 }<br>
-@synthesize what; // expected-note 2 {{'what' declared here}}<br>
+@synthesize what; // expected-note {{'what' declared here}}<br>
 @end<br>
<br>
 @implementation Bar // expected-warning {{cannot find interface declaration for}}<br>
<br>
Modified: cfe/trunk/test/SemaObjC/error-outof-scope-property-use.m<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/error-outof-scope-property-use.m?rev=192594&r1=192593&r2=192594&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/error-outof-scope-property-use.m?rev=192594&r1=192593&r2=192594&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/SemaObjC/error-outof-scope-property-use.m (original)<br>
+++ cfe/trunk/test/SemaObjC/error-outof-scope-property-use.m Mon Oct 14 09:05:48 2013<br>
@@ -6,7 +6,7 @@<br>
<br>
 @interface LaunchdJobs<br>
<br>
-@property (nonatomic,retain) NSMutableDictionary *uuids_jobs; // expected-note 2 {{'_uuids_jobs' declared here}}<br>
+@property (nonatomic,retain) NSMutableDictionary *uuids_jobs; // expected-note {{'_uuids_jobs' declared here}}<br>
<br>
 @end<br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>