https://github.com/llvmbot updated https://github.com/llvm/llvm-project/pull/187226
>From badd894eb6b9057ff7310dadd1885befd82fb0a4 Mon Sep 17 00:00:00 2001 From: Younan Zhang <[email protected]> Date: Tue, 17 Mar 2026 08:23:52 +0800 Subject: [PATCH] [Clang] Fix a concept subsumption bug when template depths are adjusted (#186735) We cannot reuse the cached normalization results if any template depth adjustments (in subsumption checking) are involved. Fixes https://github.com/llvm/llvm-project/issues/186624 (cherry picked from commit 13138b3cb90cda070e47d24f5f73f47dc2ad9c4a) --- clang/lib/Sema/SemaConcept.cpp | 10 +++++++++- clang/test/SemaTemplate/concepts.cpp | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index f55f3a9a61ab8..e17332ac90980 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -2544,7 +2544,15 @@ bool Sema::IsAtLeastAsConstrained(const NamedDecl *D1, } SubsumptionChecker SC(*this); - std::optional<bool> Subsumes = SC.Subsumes(D1, AC1, D2, AC2); + // Associated declarations are used as a cache key in the event they were + // normalized earlier during concept checking. However we cannot reuse these + // cached results if any of the template depths have been adjusted. + const NamedDecl *DeclAC1 = D1, *DeclAC2 = D2; + if (Depth2 > Depth1) + DeclAC1 = nullptr; + else if (Depth1 > Depth2) + DeclAC2 = nullptr; + std::optional<bool> Subsumes = SC.Subsumes(DeclAC1, AC1, DeclAC2, AC2); if (!Subsumes) { // Normalization failed return true; diff --git a/clang/test/SemaTemplate/concepts.cpp b/clang/test/SemaTemplate/concepts.cpp index d93391baf9926..da6e29003f7f0 100644 --- a/clang/test/SemaTemplate/concepts.cpp +++ b/clang/test/SemaTemplate/concepts.cpp @@ -1659,6 +1659,25 @@ void foo() { call(""); } } +namespace GH186624 { + +template <class T> +concept C = __is_unsigned(T); + +template <C T> +struct encoder_interface {}; + +template <template <C> class CodecInterface, C T> +CodecInterface<T>* create_codec() { + return nullptr; +} + +encoder_interface<unsigned>* create_encoder() { + return create_codec<encoder_interface, unsigned>(); +} + +} + namespace GH170856 { template <unsigned N, unsigned M> struct symbol_text { _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
