]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: alias of decltype(lambda) is opaque [PR116714, PR107390]
authorPatrick Palka <ppalka@redhat.com>
Wed, 18 Sep 2024 17:50:43 +0000 (13:50 -0400)
committerPatrick Palka <ppalka@redhat.com>
Wed, 18 Sep 2024 17:50:43 +0000 (13:50 -0400)
commit82c2acd0bc4411524a8248fcdce219927d921a71
tree934e416ed00fbdabacd2766bc3001d02379b4b36
parentfe1ed68000d5e9d41ed48ef1202fd21c8b8c9ff8
c++: alias of decltype(lambda) is opaque [PR116714, PR107390]

Here for

  using type = decltype([]{});
  static_assert(is_same_v<type, type>);

we strip the alias ahead of time during template argument coercion
which effectively transforms the template-id into

  is_same_v<decltype([]{}), decltype([]{})>

which is wrong because later substitution into the template-id will
produce two new lambdas with distinct types and cause is_same_v to
return false.

This demonstrates that such aliases should be considered opaque (a
notion that we recently introduced in r15-2331-g523836716137d0).
(An alternative solution might be to consider memoizing lambda-expr
substitution rather than always producing a new lambda, but this is
much simpler.)

PR c++/116714
PR c++/107390

gcc/cp/ChangeLog:

* pt.cc (dependent_opaque_alias_p): Also return true for a
decltype(lambda) alias.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/lambda-uneval18.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp2a/lambda-uneval18.C [new file with mode: 0644]