Skip to content

Commit

Permalink
[clang] always use resolved arguments for default argument deduction
Browse files Browse the repository at this point in the history
This fixes a regression introduced with the changes in
#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.
  • Loading branch information
mizvekov committed Jun 7, 2024
1 parent ac02168 commit df6049f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
13 changes: 6 additions & 7 deletions clang/lib/Sema/SemaTemplateDeduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,20 +712,19 @@ 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<TemplateArgument> AResolved =
SA->getCanonicalTypeInternal()
->castAs<TemplateSpecializationType>()
->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.
Expand Down
16 changes: 16 additions & 0 deletions clang/test/SemaTemplate/cwg2398.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,19 @@ namespace consistency {
// new-error@-1 {{ambiguous partial specializations}}
} // namespace t2
} // namespace consistency

namespace regression1 {
template <typename T, typename Y> struct map {};
template <typename T> class foo {};

template <template <typename...> class MapType, typename Value>
Value bar(MapType<int, Value> map);

template <template <typename...> class MapType, typename Value>
Value bar(MapType<int, foo<Value>> map);

void aux() {
map<int, foo<int>> input;
bar(input);
}
} // namespace regression1

0 comments on commit df6049f

Please sign in to comment.