]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: harmless use of 'this' rejected despite P2280R4 [PR118249]
authorPatrick Palka <ppalka@redhat.com>
Sat, 5 Apr 2025 19:22:48 +0000 (15:22 -0400)
committerPatrick Palka <ppalka@redhat.com>
Sat, 5 Apr 2025 19:22:48 +0000 (15:22 -0400)
commitf60570b26446781c0205981804f6aa4ff1708b12
tree3a89d8df52811aef97765019b414d1887beea9a4
parent3026daa8edcc0d04ba6facdab84c5854255e55c6
c++: harmless use of 'this' rejected despite P2280R4 [PR118249]

Here the implicit use of 'this' in inner.size() template argument was
being rejected despite P2280R4 relaxations, due to the special *this
handling in the INDIRECT_REF case of potential_constant_expression_1.

This handling was originally added by r196737 as part of fixing PR56481,
and it seems obsolete especially in light of P2280R4.  There doesn't
seem to be a good reason that we need to handle *this specially from
other dereferences.

This patch therefore removes this special handling.  As a side benefit
we now correctly reject some *reinterpret_cast<...>(...) constructs
earlier, via p_c_e_1 rather than via constexpr evaluation (because the
removed STRIP_NOPS step meant we'd overlook such casts), which causes a
couple of diagnostic changes (for the better).

PR c++/118249

gcc/cp/ChangeLog:

* constexpr.cc (potential_constant_expression_1)
<case INDIRECT_REF>: Remove obsolete *this handling.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-reinterpret2.C: Expect error at
call site of the non-constexpr functions.
* g++.dg/cpp23/constexpr-nonlit12.C: Likewise.
* g++.dg/cpp0x/constexpr-ref14.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/constexpr.cc
gcc/testsuite/g++.dg/cpp0x/constexpr-ref14.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/constexpr-reinterpret2.C
gcc/testsuite/g++.dg/cpp23/constexpr-nonlit12.C