hokein created this revision. hokein added a reviewer: sammccall. Herald added a project: clang.
The DependentNameType must have a non-null NSS. This property could be violated during typo correction. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D82738 Files: clang/lib/Sema/SemaTemplate.cpp clang/test/Parser/cxx-template-decl.cpp Index: clang/test/Parser/cxx-template-decl.cpp =================================================================== --- clang/test/Parser/cxx-template-decl.cpp +++ clang/test/Parser/cxx-template-decl.cpp @@ -286,3 +286,16 @@ template<int> int b; template<int> auto f() -> b<0>; // expected-error +{{}} } + +namespace NoCrashOnNullNNSTypoCorrection { + +int AddObservation(); // expected-note {{declared here}} + +template <typename T, typename... Args> +class UsingImpl {}; +class AddObservation { + using Using = + UsingImpl<AddObservationFn, const int>; // expected-error {{use of undeclared identifier 'AddObservationFn'; did you mean}} +}; + +} Index: clang/lib/Sema/SemaTemplate.cpp =================================================================== --- clang/lib/Sema/SemaTemplate.cpp +++ clang/lib/Sema/SemaTemplate.cpp @@ -4866,6 +4866,11 @@ if (Result.getAsSingle<TypeDecl>() || 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
Index: clang/test/Parser/cxx-template-decl.cpp =================================================================== --- clang/test/Parser/cxx-template-decl.cpp +++ clang/test/Parser/cxx-template-decl.cpp @@ -286,3 +286,16 @@ template<int> int b; template<int> auto f() -> b<0>; // expected-error +{{}} } + +namespace NoCrashOnNullNNSTypoCorrection { + +int AddObservation(); // expected-note {{declared here}} + +template <typename T, typename... Args> +class UsingImpl {}; +class AddObservation { + using Using = + UsingImpl<AddObservationFn, const int>; // expected-error {{use of undeclared identifier 'AddObservationFn'; did you mean}} +}; + +} Index: clang/lib/Sema/SemaTemplate.cpp =================================================================== --- clang/lib/Sema/SemaTemplate.cpp +++ clang/lib/Sema/SemaTemplate.cpp @@ -4866,6 +4866,11 @@ if (Result.getAsSingle<TypeDecl>() || 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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits