[typo-correction] Apply name specifier corrections when forming a NNS
authorReid Kleckner <rnk@google.com>
Tue, 16 Feb 2016 19:16:20 +0000 (19:16 +0000)
committerReid Kleckner <rnk@google.com>
Tue, 16 Feb 2016 19:16:20 +0000 (19:16 +0000)
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.

llvm-svn: 260993

clang/lib/Sema/SemaCXXScopeSpec.cpp
clang/test/SemaCXX/typo-correction-crash.cpp

index f7aace6..2e774dd 100644 (file)
@@ -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());
index f01facd..6349937 100644 (file)
@@ -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'?}}