diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -4844,10 +4844,7 @@ CXXScopeSpec SS; DeclarationNameInfo NameInfo; - if (DeclRefExpr *ArgExpr = dyn_cast(Arg.getAsExpr())) { - SS.Adopt(ArgExpr->getQualifierLoc()); - NameInfo = ArgExpr->getNameInfo(); - } else if (DependentScopeDeclRefExpr *ArgExpr = + if (DependentScopeDeclRefExpr *ArgExpr = dyn_cast(Arg.getAsExpr())) { SS.Adopt(ArgExpr->getQualifierLoc()); NameInfo = ArgExpr->getNameInfo(); @@ -4866,6 +4863,7 @@ if (Result.getAsSingle() || Result.getResultKind() == LookupResult::NotFoundInCurrentInstantiation) { + assert(SS.getScopeRep() && "dependent scope expr must has a scope!"); // Suggest that the user add 'typename' before the NNS. SourceLocation Loc = AL.getSourceRange().getBegin(); Diag(Loc, getLangOpts().MSVCCompat diff --git a/clang/test/Parser/cxx-template-decl.cpp b/clang/test/Parser/cxx-template-decl.cpp --- a/clang/test/Parser/cxx-template-decl.cpp +++ b/clang/test/Parser/cxx-template-decl.cpp @@ -286,3 +286,17 @@ template int b; template auto f() -> b<0>; // expected-error +{{}} } + +namespace NoCrashOnNullNNSTypoCorrection { + +int AddObservation(); // expected-note {{declared here}} + +template // expected-note {{template parameter is declared here}} +class UsingImpl {}; +class AddObservation { + using Using = + UsingImpl; // expected-error {{use of undeclared identifier 'AddObservationFn'; did you mean}} \ + expected-error {{template argument for template type parameter must be a type}} +}; + +}