https://github.com/zyn0217 updated https://github.com/llvm/llvm-project/pull/185608
>From 9b231a1b8c53155a989102f6795de6b6909f4a55 Mon Sep 17 00:00:00 2001 From: Younan Zhang <[email protected]> Date: Tue, 10 Mar 2026 17:30:02 +0800 Subject: [PATCH 1/2] [Clang] Address feedback in PR183010 As discussed there, MLTAL::isAnyArgInstantiationDependent became misleading after that patch: for type template arguments, it is actually checking whether the canonical types are dependent and for expression template arguments, it's checking the dependence of the expressions. We now rename it to MLTAL::isAnyArgDependent. --- clang/include/clang/Sema/Template.h | 5 ++--- clang/lib/Sema/SemaConcept.cpp | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Sema/Template.h b/clang/include/clang/Sema/Template.h index 0be46e69f1b6f..2215c5d610c94 100644 --- a/clang/include/clang/Sema/Template.h +++ b/clang/include/clang/Sema/Template.h @@ -185,13 +185,12 @@ enum class TemplateSubstitutionKind : char { return !(*this)(Depth, Index).isNull(); } - bool isAnyArgInstantiationDependent(const ASTContext &C) const { + bool isAnyArgDependent(const ASTContext &C) const { for (ArgumentListLevel ListLevel : TemplateArgumentLists) for (const TemplateArgument &TA : ListLevel.Args) // There might be null template arguments representing unused template // parameter mappings in an MLTAL during concept checking. - if (!TA.isNull() && - C.getCanonicalTemplateArgument(TA).isInstantiationDependent()) + if (!TA.isNull() && C.getCanonicalTemplateArgument(TA).isDependent()) return true; return false; } diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index 38791940247cb..a51c3545ac82b 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -1154,7 +1154,7 @@ static bool CheckConstraintSatisfaction( return false; } - if (TemplateArgsLists.isAnyArgInstantiationDependent(S.Context)) { + if (TemplateArgsLists.isAnyArgDependent(S.Context)) { // No need to check satisfaction for dependent constraint expressions. Satisfaction.IsSatisfied = true; return false; >From dd6d99fcfe2d03ab0a4ee1e3f6e6ea7826d90aa7 Mon Sep 17 00:00:00 2001 From: Younan Zhang <[email protected]> Date: Wed, 11 Mar 2026 10:52:57 +0800 Subject: [PATCH 2/2] Address feedback --- clang/include/clang/Sema/Template.h | 4 ++-- clang/lib/Sema/SemaConcept.cpp | 8 +++++--- .../test/SemaTemplate/concepts-using-decl.cpp | 13 +++++++++++++ clang/test/SemaTemplate/concepts.cpp | 18 ++++++++++++++++-- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/Sema/Template.h b/clang/include/clang/Sema/Template.h index 2215c5d610c94..1da05178b1163 100644 --- a/clang/include/clang/Sema/Template.h +++ b/clang/include/clang/Sema/Template.h @@ -185,12 +185,12 @@ enum class TemplateSubstitutionKind : char { return !(*this)(Depth, Index).isNull(); } - bool isAnyArgDependent(const ASTContext &C) const { + bool isAnyArgumentDependent() const { for (ArgumentListLevel ListLevel : TemplateArgumentLists) for (const TemplateArgument &TA : ListLevel.Args) // There might be null template arguments representing unused template // parameter mappings in an MLTAL during concept checking. - if (!TA.isNull() && C.getCanonicalTemplateArgument(TA).isDependent()) + if (!TA.isNull() && TA.isDependent()) return true; return false; } diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index a51c3545ac82b..4899fa4c947e2 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -456,7 +456,9 @@ class HashParameterMapping : public RecursiveASTVisitor<HashParameterMapping> { for (auto &ArgLoc : Mapping) { TemplateArgument Canonical = SemaRef.Context.getCanonicalTemplateArgument(ArgLoc.getArgument()); - // We don't want sugars to impede the profile of cache. + // We don't want sugars to impede the profile performance of cache. + // FIXME: Substituting into type sugars may introduce failures. Ignoring + // differences in type sugar might not be feasible. UsedTemplateArgs.push_back(Canonical); TraverseTemplateArgument(Canonical); } @@ -1154,8 +1156,8 @@ static bool CheckConstraintSatisfaction( return false; } - if (TemplateArgsLists.isAnyArgDependent(S.Context)) { - // No need to check satisfaction for dependent constraint expressions. + if (TemplateArgsLists.isAnyArgumentDependent()) { + // No need to check satisfaction for dependent template arguments. Satisfaction.IsSatisfied = true; return false; } diff --git a/clang/test/SemaTemplate/concepts-using-decl.cpp b/clang/test/SemaTemplate/concepts-using-decl.cpp index 41f7b6d2f8faa..64c3058f67d37 100644 --- a/clang/test/SemaTemplate/concepts-using-decl.cpp +++ b/clang/test/SemaTemplate/concepts-using-decl.cpp @@ -197,3 +197,16 @@ struct child : base<int> { }; } + +// FIXME: The concept cache should consider type sugars in some instantiation-dependent context. +namespace instantiation_dependent { + +template <class T> concept C = sizeof(T) >= 1; +template <class U> using X = int; +template <class> concept D = C<X<int>>; +// D<V> is computed as sizeof(int) >= 1 and it affects the result of both C<X<V&>> and C<X<void&>>, +// though C<X<void&>> is invalid. We should reject it. +template <D V> requires C<X<V&>> struct Y {}; +Y<void> y; + +} diff --git a/clang/test/SemaTemplate/concepts.cpp b/clang/test/SemaTemplate/concepts.cpp index 1d2ada3e0a398..89436f75f7195 100644 --- a/clang/test/SemaTemplate/concepts.cpp +++ b/clang/test/SemaTemplate/concepts.cpp @@ -1716,10 +1716,24 @@ void f() = delete; struct Bar {}; -template <typename T> using Foo = Bar; +template <typename> using Foo = Bar; -template <typename T> void use() { +template <int T> + requires true +void f2() {} + +template <int T> + requires false +void f2() = delete; + +template <int> constexpr auto Value = 1; + +template <template <typename> class> using FooTemp = Bar; + +template <typename T, int N, template <typename> class C> void use() { f<Foo<T>>(); + f2<Value<N>>(); + f<FooTemp<C>>(); } } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
