https://github.com/ilya-biryukov created https://github.com/llvm/llvm-project/pull/100144
Not for submission yet. Will eventually aim to fix #100095. The current approach should not be correct as it would have *too* much sugar in turn. We should also make sure the final substitution arguments do not contain any sugar. It does address the crash, though, so probably something along that diretion is needed, e.g. need to check if `decltype()` that's not type-dependent, but instantiation-dependent works correctly and follow the approach taken there. >From 20c9e54bc2e30864592b74db6ed1eeeddeacca50 Mon Sep 17 00:00:00 2001 From: Ilya Biryukov <ibiryu...@google.com> Date: Tue, 23 Jul 2024 17:52:19 +0200 Subject: [PATCH] [Sema] Avoid excessive desuraging in template deduction Not for submission yet. Will eventually aim to fix #100095. The current approach should not be correct as it would have *too* much sugar in turn. We should also make sure the final substitution arguments do not contain any sugar. It does address the crash, though, so probably something along that diretion is needed, e.g. need to check if `decltype()` that's not type-dependent, but instantiation-dependent works correctly and follow the approach taken there. --- clang/lib/Sema/SemaTemplateDeduction.cpp | 11 ++++--- .../test/SemaTemplate/variadic-no-mention.cpp | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 clang/test/SemaTemplate/variadic-no-mention.cpp diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index b7b857ebf804b..7fc595bd60225 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -688,10 +688,7 @@ DeduceTemplateSpecArguments(Sema &S, TemplateParameterList *TemplateParams, // FIXME: To preserve sugar, the TST needs to carry sugared resolved // arguments. - ArrayRef<TemplateArgument> PResolved = - TP->getCanonicalTypeInternal() - ->castAs<TemplateSpecializationType>() - ->template_arguments(); + ArrayRef<TemplateArgument> PResolved = TP->template_arguments(); QualType UA = A; std::optional<NestedNameSpecifier *> NNS; @@ -951,10 +948,12 @@ class PackDeductionScope { // Skip over the pack elements that were expanded into separate arguments. // If we partially expanded, this is the number of partial arguments. - if (IsPartiallyExpanded) + if (IsPartiallyExpanded) { PackElements += NumPartialPackArgs; - else if (IsExpanded) + } else if (IsExpanded) { + assert(FixedNumExpansions.has_value()); PackElements += *FixedNumExpansions; + } for (auto &Pack : Packs) { if (Info.PendingDeducedPacks.size() > Pack.Index) diff --git a/clang/test/SemaTemplate/variadic-no-mention.cpp b/clang/test/SemaTemplate/variadic-no-mention.cpp new file mode 100644 index 0000000000000..09d860249c31d --- /dev/null +++ b/clang/test/SemaTemplate/variadic-no-mention.cpp @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics + +template <class... T> +struct Types {}; +template <int& field> +using Forget = int; +template <int&... fields> +using SeqKey = Types<Forget<fields>...>; + +template <typename Key, typename Value> +struct HelperBase { + using ResponseParser = Key(); + HelperBase(ResponseParser response_parser) {} +}; +template <int&... fields> +SeqKey<fields...> Parser(); + +template <int&... fields> +struct Helper : public HelperBase<SeqKey<fields...>, double> { + using Key = SeqKey<fields...>; + using Value = double; + using ParentClass = HelperBase<Key, Value>; + Helper() : ParentClass(Parser<fields...>) {} +}; + +void test() { + Helper<>(); +} + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits