Skip to content

Commit 3f9e712

Browse files
authored
[Clang] Drop unrelated template arguments in substituted parameter mapping (#163221)
The unused template arguments living in different levels would confuse the substitution otherwise. This is a trunk regression, so no release note. Fixes #163057
1 parent 66bf252 commit 3f9e712

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

clang/include/clang/Sema/Template.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ enum class TemplateSubstitutionKind : char {
205205

206206
/// Add a new outmost level to the multi-level template argument
207207
/// list.
208-
/// A 'Final' substitution means that Subst* nodes won't be built
209-
/// for the replacements.
208+
/// A 'Final' substitution means that these Args don't need to be
209+
/// resugared later.
210210
void addOuterTemplateArguments(Decl *AssociatedDecl, ArgList Args,
211211
bool Final) {
212212
assert(!NumRetainedOuterLevels &&

clang/lib/Sema/SemaConcept.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,9 @@ ConstraintSatisfactionChecker::SubstitutionInTemplateArguments(
606606
Constraint.mappingOccurenceList();
607607
// The empty MLTAL situation should only occur when evaluating non-dependent
608608
// constraints.
609-
if (!MLTAL.getNumSubstitutedLevels())
610-
MLTAL.addOuterTemplateArguments(TD, {}, /*Final=*/false);
611-
SubstitutedOuterMost =
612-
llvm::to_vector_of<TemplateArgument>(MLTAL.getOutermost());
609+
if (MLTAL.getNumSubstitutedLevels())
610+
SubstitutedOuterMost =
611+
llvm::to_vector_of<TemplateArgument>(MLTAL.getOutermost());
613612
unsigned Offset = 0;
614613
for (unsigned I = 0, MappedIndex = 0; I < Used.size(); I++) {
615614
TemplateArgument Arg;
@@ -627,8 +626,10 @@ ConstraintSatisfactionChecker::SubstitutionInTemplateArguments(
627626
if (Offset < SubstitutedOuterMost.size())
628627
SubstitutedOuterMost.erase(SubstitutedOuterMost.begin() + Offset);
629628

630-
MLTAL.replaceOutermostTemplateArguments(TD, SubstitutedOuterMost);
631-
return std::move(MLTAL);
629+
MultiLevelTemplateArgumentList SubstitutedTemplateArgs;
630+
SubstitutedTemplateArgs.addOuterTemplateArguments(TD, SubstitutedOuterMost,
631+
/*Final=*/false);
632+
return std::move(SubstitutedTemplateArgs);
632633
}
633634

634635
ExprResult ConstraintSatisfactionChecker::EvaluateSlow(

clang/test/SemaTemplate/concepts.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,31 @@ concept IsEntitySpec =
14161416

14171417
}
14181418

1419+
namespace case8 {
1420+
1421+
template <class T>
1422+
struct type_identity {
1423+
using type = T;
1424+
};
1425+
1426+
template <typename Inner>
1427+
struct Cat {};
1428+
1429+
template <typename T>
1430+
concept CatConcept = requires {
1431+
[]<class Inner>(type_identity<Cat<Inner>>) {}(type_identity<T>{});
1432+
};
1433+
1434+
template <typename Dummy>
1435+
struct Feeder {
1436+
template <CatConcept Dummy2>
1437+
void feed() noexcept {}
1438+
};
1439+
1440+
void main() { Feeder<int>{}.feed<Cat<int>>(); }
1441+
1442+
}
1443+
14191444
}
14201445

14211446
namespace GH162125 {

0 commit comments

Comments
 (0)