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 @@ -4866,6 +4866,11 @@ if (Result.getAsSingle() || Result.getResultKind() == LookupResult::NotFoundInCurrentInstantiation) { + if (SS.isEmpty()) + // bail out if we don't have a NNS, this could be happened during + // typo correction in error recovery. + // A dependent name type should have a non-null NNS. + return true; // 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,16 @@ template int b; template auto f() -> b<0>; // expected-error +{{}} } + +namespace NoCrashOnNullNNSTypoCorrection { + +int AddObservation(); // expected-note {{declared here}} + +template +class UsingImpl {}; +class AddObservation { + using Using = + UsingImpl; // expected-error {{use of undeclared identifier 'AddObservationFn'; did you mean}} +}; + +}