[clang] [libcxx] [Clang] Normalize constraints before checking for satisfaction (PR #141776)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 12 20:20:52 PDT 2025


================
@@ -1257,4 +1256,35 @@ template <typename T> concept PerfectSquare = [](){} // expected-note 2{{here}}
 ([](auto) { return true; }) < PerfectSquare <class T>;
 // expected-error at -1 {{declaration of 'T' shadows template parameter}} \
 // expected-error at -1 {{a concept definition cannot refer to itself}}
+
+}
+namespace GH61811{
+template <class T> struct A { static const int x = 42; };
+template <class Ta> concept A42 = A<Ta>::x == 42;
+template <class Tv> concept Void = __is_same_as(Tv, void);
+template <class Tb, class Ub> concept A42b = Void<Tb> || A42<Ub>;
+template <class Tc> concept R42c = A42b<Tc, Tc&>;
+static_assert (R42c<void>);
+}
+
+namespace parameter_mapping_regressions {
+
+namespace case1 {
+
+template <template <class> class> using __meval = struct __q;
+template <template <class> class _Tp>
+concept __mvalid = requires { typename __meval<_Tp>; };
+template <class _Fn>
+concept __minvocable = __mvalid<_Fn::template __f>;
+template <class...> struct __mdefer_;
+template <class _Fn, class... _Args>
+  requires __minvocable<_Fn>
+struct __mdefer_<_Fn, _Args...> {};
+template <class = __q> struct __mtransform {
+  template <class> using __f = int;
+};
+struct __completion_domain_or_none_ : __mdefer_<__mtransform<>> {};
+
+}
----------------
zyn0217 wrote:

@mizvekov Here is the regression why I removed that assert in TemplateArgumentLoc.

So basically we want to build the parameter mapping of __minvocable<Fn> from line 1281. We use template rewrite mechanism, and we end up substituting `_Fn::template __f` into template template parameter on line 1275.

I noticed your last removal of DTST patch and I tried with it locally, but unfortunately it doesn't fix that assertion failure where that template template parameter doesn't have the same NNS with the rewritten template argument.

The rewritten template argument comes from CheckTemplateArguments, which is necessary to correctly preserve packs in other cases.

We chose to use rewritten mode in very early developing stage because we had trouble with Subst nodes and lambdas, and it was impossible to fix that without rewriting half of clang.

I tried rebuilding that TemplateName with its NNS cleared, but it turned out I have to handle so many types in Instantiator which is a bit clumsy. (And I failed some regressions too!)

Maybe we are having the same problem with CTAD guides, but I didn't come up with a case so far.

Do you have any suggestions for such a case?




https://github.com/llvm/llvm-project/pull/141776


More information about the cfe-commits mailing list