llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Yanzuo Liu (zwuis) <details> <summary>Changes</summary> `getDepthAndIndex(const NamedDecl *)` assumes its parameter refers to a template parameter. Bail out before calling it for function parameter packs. Fix #<!-- -->28877. Fix #<!-- -->213760. --- Full diff: https://github.com/llvm/llvm-project/pull/215235.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.md (+2) - (modified) clang/include/clang/Sema/SemaInternal.h (+7-5) - (modified) clang/test/SemaTemplate/deduction-crash.cpp (+16) ``````````diff diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index fc947d05fad83..75a5afd7a2648 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -445,6 +445,8 @@ features cannot lower the translation-unit ABI level; affect C++26 constexpr structured bindings and expansion statements, but also affects some uses of plain structured bindings. (#GH211930) +- Fixed a crash during template argument deduction where a function parameter pack is referenced by other types in the function type. (GH28877, GH213760) + #### Bug Fixes to AST Handling - Fixed a non-deterministic ordering of unused local typedefs that made diff --git a/clang/include/clang/Sema/SemaInternal.h b/clang/include/clang/Sema/SemaInternal.h index 8f6041b5f00e4..58b9ec537b4bd 100644 --- a/clang/include/clang/Sema/SemaInternal.h +++ b/clang/include/clang/Sema/SemaInternal.h @@ -77,11 +77,13 @@ inline std::optional<std::pair<unsigned, unsigned>> getDepthAndIndex(UnexpandedParameterPack UPP) { if (const auto *TTP = dyn_cast<const TemplateTypeParmType *>(UPP.first)) return std::make_pair(TTP->getDepth(), TTP->getIndex()); - if (isa<NamedDecl *>(UPP.first)) - return getDepthAndIndex(cast<NamedDecl *>(UPP.first)); - assert((isa<const TemplateSpecializationType *, - const SubstBuiltinTemplatePackType *>(UPP.first))); - return std::nullopt; + if (isa<const TemplateSpecializationType *, + const SubstBuiltinTemplatePackType *>(UPP.first)) + return std::nullopt; + const auto *ND = cast<NamedDecl *>(UPP.first); + if (isa<ParmVarDecl>(ND)) + return std::nullopt; + return getDepthAndIndex(ND); } class TypoCorrectionConsumer : public VisibleDeclConsumer { diff --git a/clang/test/SemaTemplate/deduction-crash.cpp b/clang/test/SemaTemplate/deduction-crash.cpp index e7018fd0d8338..2b0befb34a2df 100644 --- a/clang/test/SemaTemplate/deduction-crash.cpp +++ b/clang/test/SemaTemplate/deduction-crash.cpp @@ -177,3 +177,19 @@ namespace GH177545 { template<decltype(auto)()() volatile throw() -> char> // expected-error {{'decltype(auto)' can only be used as a return type in a function declaration}} struct T2; // expected-error@* {{function cannot return function type 'auto () volatile throw() -> decltype(auto)'}} } + +namespace GH28877 { +template <typename...> struct S; +template <typename... Ts> auto f(Ts... args) -> S<decltype(args)...>; +extern template auto f() -> S<>; +} + +namespace GH46548 { +template <typename... Ts> void a(Ts... args1, char... args2[][sizeof args1]); +extern template void a(); +} + +namespace GH213760 { +template <typename... Ts> void f(Ts... args, decltype(args)...); +void g() { f(); } +} `````````` </details> https://github.com/llvm/llvm-project/pull/215235 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
