]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: decltype of (non-captured variable) [PR83167]
authorPatrick Palka <ppalka@redhat.com>
Fri, 8 Dec 2023 21:57:13 +0000 (16:57 -0500)
committerPatrick Palka <ppalka@redhat.com>
Fri, 8 Dec 2023 21:57:13 +0000 (16:57 -0500)
commitd9965fef40794d548021d2e34844e5fafeca4ce5
treed1846780678b641da3ab33f077b3c0c4bac3ef9c
parent0bef72539e585d13941987369cf34726a7ac5b2e
c++: decltype of (non-captured variable) [PR83167]

For decltype((x)) within a lambda where x is not captured, we dubiously
require that the lambda has a capture default, unlike for decltype(x).
But according to [expr.prim.id.unqual]/3 we should just ignore the lambda
in this case.  This patch narrowly fixes this issue by disabling the
capture_decltype handling and falling back to the ordinary handling when
the innermost lambda has no capture-default.  In fact, we can restrict
the special handling to only by-copy lambdas since that's what
[expr.prim.id.unqual]/3 is concerned with; for by-ref implicit captures
both code paths should give the same result anyway.

During review some other issues were discovered which are documented in
a new FIXME.

PR c++/83167

gcc/cp/ChangeLog:

* semantics.cc (capture_decltype): Inline into its only caller ...
(finish_decltype_type): ... here.  Update nearby comment to refer
to recent standard.  Add FIXME.  Restrict uncaptured variable type
transformation to happen only for lambdas with a by-copy
capture-default.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/lambda/lambda-decltype4.C: New test.
gcc/cp/semantics.cc
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-decltype4.C [new file with mode: 0644]