]> gcc.gnu.org Git - gcc.git/commit
c++: potentiality of templated memfn call [PR109480]
authorPatrick Palka <ppalka@redhat.com>
Sun, 7 May 2023 14:24:49 +0000 (10:24 -0400)
committerPatrick Palka <ppalka@redhat.com>
Sun, 7 May 2023 14:24:49 +0000 (10:24 -0400)
commit7f4840ddef9746ab591c78ecdd750e3b18aa1ce6
tree3f5d8e64336e092b7f95b9ca3d9e7bbdb7b11328
parentb05b529125fa51e24b35ef9ac13b875521c9b052
c++: potentiality of templated memfn call [PR109480]

Here we're incorrectly deeming the templated call a.g() inside b's
initializer as potentially constant, despite g being non-constexpr,
which leads to us needlessly instantiating the initializer ahead of time
and which subsequently triggers a bug in access checking deferral (to be
fixed by the follow-up patch).

This patch fixes this by calling get_fns earlier during CALL_EXPR
potentiality checking so that when we extract a FUNCTION_DECL out of a
templated member function call (whose overall callee is typically a
COMPONENT_REF) we do the usual constexpr-eligibility checking for it.

In passing, I noticed the nearby special handling of the object argument
of a non-static member function call is effectively the same as the
generic argument handling a few lines below.  So this patch just gets
rid of this special handling; otherwise we'd have to adapt it to handle
templated versions of such calls.

PR c++/109480

gcc/cp/ChangeLog:

* constexpr.cc (potential_constant_expression_1) <case CALL_EXPR>:
Reorganize to call get_fns sooner.  Remove special handling of
the object argument of a non-static member function call.  Remove
dead store to 'fun'.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/noexcept59.C: Make e() constexpr so that the
expected "without object" diagnostic isn't replaced by a
"call to non-constexpr function" diagnostic.
* g++.dg/template/non-dependent25.C: New test.
gcc/cp/constexpr.cc
gcc/testsuite/g++.dg/cpp0x/noexcept59.C
gcc/testsuite/g++.dg/template/non-dependent25.C [new file with mode: 0644]
This page took 0.064266 seconds and 5 git commands to generate.