From df6049fd91c95e341dd80a61e5bd173ce5837131 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Fri, 7 Jun 2024 10:32:12 -0300 Subject: [PATCH] [clang] always use resolved arguments for default argument deduction This fixes a regression introduced with the changes in https://github.com/llvm/llvm-project/pull/93433 around preservation of TemplateName sugar in template type deduction. Since the argument side TST is non-canonical, we have to extract the arguments from it's canonical type. This was done for the deduction of the TST arguments, but we missed it for the default arguments used in the deduction of the TST name. --- clang/lib/Sema/SemaTemplateDeduction.cpp | 13 ++++++------- clang/test/SemaTemplate/cwg2398.cpp | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 1011db2d2830dc..befeb38e1fe5bc 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -712,13 +712,6 @@ DeduceTemplateSpecArguments(Sema &S, TemplateParameterList *TemplateParams, if (const auto *TD = TNA.getAsTemplateDecl(); TD && TD->isTypeAlias()) return TemplateDeductionResult::Success; - // Perform template argument deduction for the template name. - if (auto Result = - DeduceTemplateArguments(S, TemplateParams, TNP, TNA, Info, - SA->template_arguments(), Deduced); - Result != TemplateDeductionResult::Success) - return Result; - // FIXME: To preserve sugar, the TST needs to carry sugared resolved // arguments. ArrayRef AResolved = @@ -726,6 +719,12 @@ DeduceTemplateSpecArguments(Sema &S, TemplateParameterList *TemplateParams, ->castAs() ->template_arguments(); + // Perform template argument deduction for the template name. + if (auto Result = DeduceTemplateArguments(S, TemplateParams, TNP, TNA, Info, + AResolved, Deduced); + Result != TemplateDeductionResult::Success) + return Result; + // Perform template argument deduction on each template // argument. Ignore any missing/extra arguments, since they could be // filled in by default arguments. diff --git a/clang/test/SemaTemplate/cwg2398.cpp b/clang/test/SemaTemplate/cwg2398.cpp index 45e74cce3a98c8..f7f69e9d4268ac 100644 --- a/clang/test/SemaTemplate/cwg2398.cpp +++ b/clang/test/SemaTemplate/cwg2398.cpp @@ -201,3 +201,19 @@ namespace consistency { // new-error@-1 {{ambiguous partial specializations}} } // namespace t2 } // namespace consistency + +namespace regression1 { + template struct map {}; + template class foo {}; + + template