hokein created this revision. hokein added a reviewer: sammccall. Herald added subscribers: usaxena95, kadircet, ilya-biryukov. Herald added a project: clang.
Fix https://github.com/clangd/clangd/issues/293 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D76320 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 @@ -273,3 +273,9 @@ namespace PR45063 { template<class=class a::template b<>> struct X {}; // expected-error {{undeclared identifier 'a'}} } + +namespace NoCrashOnEmptyNestedNameSpecifier { + template <typename FnT, + typename T = typename ABC<FnT>::template arg_t<0>> // expected-error {{no template named 'ABC'}} + void foo(FnT) {} +} Index: clang/lib/Sema/SemaTemplate.cpp =================================================================== --- clang/lib/Sema/SemaTemplate.cpp +++ clang/lib/Sema/SemaTemplate.cpp @@ -5923,12 +5923,16 @@ bool UnnamedLocalNoLinkageFinder::VisitDependentNameType( const DependentNameType* T) { - return VisitNestedNameSpecifier(T->getQualifier()); + if (auto *Q = T->getQualifier()) + return VisitNestedNameSpecifier(Q); + return false; } bool UnnamedLocalNoLinkageFinder::VisitDependentTemplateSpecializationType( const DependentTemplateSpecializationType* T) { - return VisitNestedNameSpecifier(T->getQualifier()); + if (auto *Q = T->getQualifier()) + return VisitNestedNameSpecifier(Q); + return false; } bool UnnamedLocalNoLinkageFinder::VisitPackExpansionType( @@ -5982,6 +5986,7 @@ bool UnnamedLocalNoLinkageFinder::VisitNestedNameSpecifier( NestedNameSpecifier *NNS) { + assert(NNS && "NNS must not be null!"); if (NNS->getPrefix() && VisitNestedNameSpecifier(NNS->getPrefix())) return true;
Index: clang/test/Parser/cxx-template-decl.cpp =================================================================== --- clang/test/Parser/cxx-template-decl.cpp +++ clang/test/Parser/cxx-template-decl.cpp @@ -273,3 +273,9 @@ namespace PR45063 { template<class=class a::template b<>> struct X {}; // expected-error {{undeclared identifier 'a'}} } + +namespace NoCrashOnEmptyNestedNameSpecifier { + template <typename FnT, + typename T = typename ABC<FnT>::template arg_t<0>> // expected-error {{no template named 'ABC'}} + void foo(FnT) {} +} Index: clang/lib/Sema/SemaTemplate.cpp =================================================================== --- clang/lib/Sema/SemaTemplate.cpp +++ clang/lib/Sema/SemaTemplate.cpp @@ -5923,12 +5923,16 @@ bool UnnamedLocalNoLinkageFinder::VisitDependentNameType( const DependentNameType* T) { - return VisitNestedNameSpecifier(T->getQualifier()); + if (auto *Q = T->getQualifier()) + return VisitNestedNameSpecifier(Q); + return false; } bool UnnamedLocalNoLinkageFinder::VisitDependentTemplateSpecializationType( const DependentTemplateSpecializationType* T) { - return VisitNestedNameSpecifier(T->getQualifier()); + if (auto *Q = T->getQualifier()) + return VisitNestedNameSpecifier(Q); + return false; } bool UnnamedLocalNoLinkageFinder::VisitPackExpansionType( @@ -5982,6 +5986,7 @@ bool UnnamedLocalNoLinkageFinder::VisitNestedNameSpecifier( NestedNameSpecifier *NNS) { + assert(NNS && "NNS must not be null!"); if (NNS->getPrefix() && VisitNestedNameSpecifier(NNS->getPrefix())) return true;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits