From: Patrick Palka Date: Tue, 17 Feb 2026 16:21:42 +0000 (-0500) Subject: c++: unifying LAMBDA_EXPR [PR122318] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9fe46ba8eb3f2cf41744cf8490b025f0876b9c86;p=thirdparty%2Fgcc.git c++: unifying LAMBDA_EXPR [PR122318] This patch makes the default case of unify accept LAMBDA_EXPR P/A pairs, which we can legitimately hit during alias CTAD guide overload resolution. We can also less legimitately hit this during partial specialization matching (likely IFNDR). I'm not totally sure if we want to handle them like any other non-deducible expression vs handling them separately (returning success iff they're ==). I couldn't come up with a testcase for which it mattered so I went the simpler route. PR c++/122318 PR c++/101670 gcc/cp/ChangeLog: * pt.cc (unify) : Accept LAMBDA_EXPR. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/lambda-targ20.C: New test. * g++.dg/cpp2a/lambda-targ21.C: New test. Reviewed-by: Jason Merrill --- diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 1d11b07d567..5db46cd707f 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -26650,6 +26650,7 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, return unify_success (explain_p); gcc_assert (EXPR_P (parm) || TREE_CODE (parm) == CONSTRUCTOR + || TREE_CODE (parm) == LAMBDA_EXPR || TREE_CODE (parm) == TRAIT_EXPR); expr: /* We must be looking at an expression. This can happen with diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-targ20.C b/gcc/testsuite/g++.dg/cpp2a/lambda-targ20.C new file mode 100644 index 00000000000..4d444bbe112 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-targ20.C @@ -0,0 +1,14 @@ +// PR c++/122318 +// { dg-do compile { target c++20 } } + +template +struct A { + A() { } + A(T) { } +}; + +template +using AT = A; + +AT a; +AT b = a; diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-targ21.C b/gcc/testsuite/g++.dg/cpp2a/lambda-targ21.C new file mode 100644 index 00000000000..d417d6cc3e8 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-targ21.C @@ -0,0 +1,10 @@ +// PR c++/101670 +// { dg-do compile { target c++20 } } + +template +struct A; + +template +struct A { }; // Partial specialization unusable due to lambda uniqueness + +A<0> a; // { dg-error "incomplete" }