From eb267f6ce66e53bfe2cc7a6eaea030d4df0bf2da Mon Sep 17 00:00:00 2001
From: Reid Kleckner <rnk@google.com>
Date: Tue, 16 Feb 2016 19:16:20 +0000
Subject: [PATCH] [typo-correction] Apply name specifier corrections when
 forming a NNS

Previously we would leave behind the old name specifier prefix, which
creates an invalid AST.  Other callers of CorrectTypo update their
CXXScopeSpec objects with the correction specifier if one is present.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260993 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Sema/SemaCXXScopeSpec.cpp          | 4 ++++
 test/SemaCXX/typo-correction-crash.cpp | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/lib/Sema/SemaCXXScopeSpec.cpp b/lib/Sema/SemaCXXScopeSpec.cpp
index f7aace625a9..2e774dd28ce 100644
--- a/lib/Sema/SemaCXXScopeSpec.cpp
+++ b/lib/Sema/SemaCXXScopeSpec.cpp
@@ -606,6 +606,10 @@ bool Sema::BuildCXXNestedNameSpecifier(Scope *S,
         diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest)
                                   << Name);
 
+      if (Corrected.getCorrectionSpecifier())
+        SS.MakeTrivial(Context, Corrected.getCorrectionSpecifier(),
+                       SourceRange(Found.getNameLoc()));
+
       if (NamedDecl *ND = Corrected.getFoundDecl())
         Found.addDecl(ND);
       Found.setLookupName(Corrected.getCorrection());
diff --git a/test/SemaCXX/typo-correction-crash.cpp b/test/SemaCXX/typo-correction-crash.cpp
index f01facd603e..6349937ccd9 100644
--- a/test/SemaCXX/typo-correction-crash.cpp
+++ b/test/SemaCXX/typo-correction-crash.cpp
@@ -9,3 +9,11 @@ auto check2() {
   return "s";
   return tes; // expected-error {{use of undeclared identifier 'tes'; did you mean 'test'?}}
 }
+
+namespace BarNamespace {
+namespace NestedNamespace { // expected-note {{'BarNamespace::NestedNamespace' declared here}}
+typedef int type;
+}
+}
+struct FooRecord { };
+FooRecord::NestedNamespace::type x; // expected-error {{no member named 'NestedNamespace' in 'FooRecord'; did you mean 'BarNamespace::NestedNamespace'?}}
-- 
GitLab