[clang] 3f9e712 - [Clang] Drop unrelated template arguments in substituted parameter mapping (#163221)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 14 09:01:16 PDT 2025
Author: Younan Zhang
Date: 2025-10-14T16:01:12Z
New Revision: 3f9e712402fea234bdd871948decd7ef394d0538
URL: https://github.com/llvm/llvm-project/commit/3f9e712402fea234bdd871948decd7ef394d0538
DIFF: https://github.com/llvm/llvm-project/commit/3f9e712402fea234bdd871948decd7ef394d0538.diff
LOG: [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 https://github.com/llvm/llvm-project/issues/163057
Added:
Modified:
clang/include/clang/Sema/Template.h
clang/lib/Sema/SemaConcept.cpp
clang/test/SemaTemplate/concepts.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Sema/Template.h b/clang/include/clang/Sema/Template.h
index 60c7d275f1aaf..e963439b05c98 100644
--- a/clang/include/clang/Sema/Template.h
+++ b/clang/include/clang/Sema/Template.h
@@ -205,8 +205,8 @@ enum class TemplateSubstitutionKind : char {
/// Add a new outmost level to the multi-level template argument
/// list.
- /// A 'Final' substitution means that Subst* nodes won't be built
- /// for the replacements.
+ /// A 'Final' substitution means that these Args don't need to be
+ /// resugared later.
void addOuterTemplateArguments(Decl *AssociatedDecl, ArgList Args,
bool Final) {
assert(!NumRetainedOuterLevels &&
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 9cbd1bd772f6f..87dd68269d44a 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -606,10 +606,9 @@ ConstraintSatisfactionChecker::SubstitutionInTemplateArguments(
Constraint.mappingOccurenceList();
// The empty MLTAL situation should only occur when evaluating non-dependent
// constraints.
- if (!MLTAL.getNumSubstitutedLevels())
- MLTAL.addOuterTemplateArguments(TD, {}, /*Final=*/false);
- SubstitutedOuterMost =
- llvm::to_vector_of<TemplateArgument>(MLTAL.getOutermost());
+ if (MLTAL.getNumSubstitutedLevels())
+ SubstitutedOuterMost =
+ llvm::to_vector_of<TemplateArgument>(MLTAL.getOutermost());
unsigned Offset = 0;
for (unsigned I = 0, MappedIndex = 0; I < Used.size(); I++) {
TemplateArgument Arg;
@@ -627,8 +626,10 @@ ConstraintSatisfactionChecker::SubstitutionInTemplateArguments(
if (Offset < SubstitutedOuterMost.size())
SubstitutedOuterMost.erase(SubstitutedOuterMost.begin() + Offset);
- MLTAL.replaceOutermostTemplateArguments(TD, SubstitutedOuterMost);
- return std::move(MLTAL);
+ MultiLevelTemplateArgumentList SubstitutedTemplateArgs;
+ SubstitutedTemplateArgs.addOuterTemplateArguments(TD, SubstitutedOuterMost,
+ /*Final=*/false);
+ return std::move(SubstitutedTemplateArgs);
}
ExprResult ConstraintSatisfactionChecker::EvaluateSlow(
diff --git a/clang/test/SemaTemplate/concepts.cpp b/clang/test/SemaTemplate/concepts.cpp
index 3fbe7c0ac650f..aaa20f6240e76 100644
--- a/clang/test/SemaTemplate/concepts.cpp
+++ b/clang/test/SemaTemplate/concepts.cpp
@@ -1416,6 +1416,31 @@ concept IsEntitySpec =
}
+namespace case8 {
+
+template <class T>
+struct type_identity {
+ using type = T;
+};
+
+template <typename Inner>
+struct Cat {};
+
+template <typename T>
+concept CatConcept = requires {
+ []<class Inner>(type_identity<Cat<Inner>>) {}(type_identity<T>{});
+};
+
+template <typename Dummy>
+struct Feeder {
+ template <CatConcept Dummy2>
+ void feed() noexcept {}
+};
+
+void main() { Feeder<int>{}.feed<Cat<int>>(); }
+
+}
+
}
namespace GH162125 {
More information about the cfe-commits
mailing list