<div>Doug,</div><div><br></div>This band-aid looks good to me, though adding another special flag to the correction callback object somehow seems... dirty. I've added tackling the FIXMEs for actually performing the correction to my queue of "things to address once I'm working on clang itself again". ;)<div>
<br></div><div>Thanks for taking care of the crasher for me!</div><div><br></div><div>Cheers,</div><div>Kaelyn<br><br><div class="gmail_quote">On Mon, Mar 26, 2012 at 9:54 AM, Douglas Gregor <span dir="ltr"><<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: dgregor<br>
Date: Mon Mar 26 11:54:18 2012<br>
New Revision: 153445<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=153445&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=153445&view=rev</a><br>
Log:<br>
When diagnosing an invalid out-of-line redeclaration, don't permit<br>
typo correction to introduce a nested-name-specifier; we aren't<br>
prepared to handle it here. Fixes PR12297 / <rdar://problem/11075219>.<br>
<br>
Modified:<br>
    cfe/trunk/include/clang/Sema/TypoCorrection.h<br>
    cfe/trunk/lib/Sema/SemaDecl.cpp<br>
    cfe/trunk/lib/Sema/SemaLookup.cpp<br>
    cfe/trunk/test/FixIt/typo-crash.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Sema/TypoCorrection.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/TypoCorrection.h?rev=153445&r1=153444&r2=153445&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/TypoCorrection.h?rev=153445&r1=153444&r2=153445&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/include/clang/Sema/TypoCorrection.h (original)<br>
+++ cfe/trunk/include/clang/Sema/TypoCorrection.h Mon Mar 26 11:54:18 2012<br>
@@ -205,7 +205,7 @@<br>
       : WantTypeSpecifiers(true), WantExpressionKeywords(true),<br>
         WantCXXNamedCasts(true), WantRemainingKeywords(true),<br>
         WantObjCSuper(false),<br>
-        IsObjCIvarLookup(false) {}<br>
+        IsObjCIvarLookup(false), AllowAddedQualifier(true) {}<br>
<br>
   virtual ~CorrectionCandidateCallback() {}<br>
<br>
@@ -239,6 +239,10 @@<br>
   // Temporary hack for the one case where a CorrectTypoContext enum is used<br>
   // when looking up results.<br>
   bool IsObjCIvarLookup;<br>
+<br>
+  /// \brief Whether to allow this typo correction to add a<br>
+  /// nested-name-specifier.<br>
+  bool AllowAddedQualifier;<br>
 };<br>
<br>
 /// @brief Simple template class for restricting typo correction candidates<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=153445&r1=153444&r2=153445&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=153445&r1=153444&r2=153445&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Mar 26 11:54:18 2012<br>
@@ -4478,7 +4478,14 @@<br>
 class DifferentNameValidatorCCC : public CorrectionCandidateCallback {<br>
  public:<br>
   DifferentNameValidatorCCC(CXXRecordDecl *Parent)<br>
-      : ExpectedParent(Parent ? Parent->getCanonicalDecl() : 0) {}<br>
+      : ExpectedParent(Parent ? Parent->getCanonicalDecl() : 0) {<br>
+    // Don't allow any additional qualification.<br>
+    // FIXME: It would be nice to perform this additional qualification.<br>
+    // However, DiagnoseInvalidRedeclaration is unable to handle the<br>
+    // qualification, because it doesn't know how to pass the corrected<br>
+    // nested-name-specifier through to ActOnFunctionDeclarator.<br>
+    AllowAddedQualifier = false;<br>
+  }<br>
<br>
   virtual bool ValidateCandidate(const TypoCorrection &candidate) {<br>
     if (candidate.getEditDistance() == 0)<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=153445&r1=153444&r2=153445&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=153445&r1=153444&r2=153445&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Mon Mar 26 11:54:18 2012<br>
@@ -3806,7 +3806,13 @@<br>
     }<br>
   }<br>
<br>
-  if (IsUnqualifiedLookup || (QualifiedDC && QualifiedDC->isNamespace())) {<br>
+  // Determine whether we are going to search in the various namespaces for<br>
+  // corrections.<br>
+  bool SearchNamespaces<br>
+    = getLangOpts().CPlusPlus && CCC.AllowAddedQualifier &&<br>
+      (IsUnqualifiedLookup || (QualifiedDC && QualifiedDC->isNamespace()));<br>
+<br>
+  if (IsUnqualifiedLookup || SearchNamespaces) {<br>
     // For unqualified lookup, look through all of the names that we have<br>
     // seen in this translation unit.<br>
     // FIXME: Re-add the ability to skip very unlikely potential corrections.<br>
@@ -3852,8 +3858,9 @@<br>
     return TypoCorrection();<br>
   }<br>
<br>
-  // Build the NestedNameSpecifiers for the KnownNamespaces<br>
-  if (getLangOpts().CPlusPlus) {<br>
+  // Build the NestedNameSpecifiers for the KnownNamespaces, if we're going<br>
+  // to search those namespaces.<br>
+  if (SearchNamespaces) {<br>
     // Load any externally-known namespaces.<br>
     if (ExternalSource && !LoadedExternalKnownNamespaces) {<br>
       SmallVector<NamespaceDecl *, 4> ExternalKnownNamespaces;<br>
@@ -3948,7 +3955,7 @@<br>
       break;<br>
<br>
     // Only perform the qualified lookups for C++<br>
-    if (getLangOpts().CPlusPlus) {<br>
+    if (SearchNamespaces) {<br>
       TmpRes.suppressDiagnostics();<br>
       for (llvm::SmallVector<TypoCorrection,<br>
                              16>::iterator QRI = QualifiedResults.begin(),<br>
<br>
Modified: cfe/trunk/test/FixIt/typo-crash.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/typo-crash.cpp?rev=153445&r1=153444&r2=153445&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/typo-crash.cpp?rev=153445&r1=153444&r2=153445&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/FixIt/typo-crash.cpp (original)<br>
+++ cfe/trunk/test/FixIt/typo-crash.cpp Mon Mar 26 11:54:18 2012<br>
@@ -10,3 +10,20 @@<br>
   // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} \<br>
   // expected-error {{use of undeclared identifier 't'}}<br>
  }<br>
+<br>
+// FIXME: It would be nice if we could get this correction right.<br>
+namespace PR12297 {<br>
+  namespace A {<br>
+    typedef short   T;<br>
+<br>
+    namespace B {<br>
+      typedef short   T;<br>
+<br>
+      T global();<br>
+    }<br>
+  }<br>
+<br>
+  using namespace A::B;<br>
+<br>
+  T A::global(); // expected-error{{out-of-line definition of 'global' does not match any declaration in namespace 'PR12297::A'}}<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>