public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Patrick Palka <ppalka@redhat.com>, Martin Jambor <mjambor@suse.cz>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH 1/2] c++: potentiality of templated memfn call [PR109480]
Date: Fri, 12 May 2023 13:13:21 -0400	[thread overview]
Message-ID: <1e148389-a5b1-bb4e-858d-4bd8bb6928f6@redhat.com> (raw)
In-Reply-To: <CAMOnLZb=jn3ybie26DNNKxUPRD3n3Nd5JpCVDT=0QHzRemOqDg@mail.gmail.com>

On 5/12/23 13:02, Patrick Palka wrote:
> Hi Martin,
> 
> On Fri, May 12, 2023 at 12:13 PM Martin Jambor <mjambor@suse.cz> wrote:
>>
>> Hello Patrick,
>>
>> On Wed, May 03 2023, Patrick Palka via Gcc-patches wrote:
>>>
>> [...]
>>>
>>> Subject: [PATCH] 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 wastefully instantiating the initializer ahead of time,
>>> which incidentally tiggers a bug in access checking deferral (to be
>>> fixed by the subsequent patch).
>>>
>>> This patch fixes this by calling get_fns earlier during CALL_EXPR
>>> potentiality checking so that we're able to extract a FUNCTION_DECL out
>>> of a templated member function call (whose overall is typically a
>>> COMPONENT_REF) and to the usual checking if the called function is
>>> constexpr etc.
>>>
>>> In passing, I noticed potential_constant_expression_1's 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 later.  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'.
>>>
>>
>> This patch makes g++ no longer accept the following, complaining that
>> get_subsys is non-constexpr (with just -std=c++17 -S), which is of
>> course auto-reduced from a much larger source file from Ceph:
>>
>> ----------------------------------- 8< -----------------------------------
>> struct {
>>    void get_subsys();
>> } PriorSet_dpp;
>> struct PriorSet {
>>    template <typename> PriorSet();
>> };
>> template <typename> PriorSet::PriorSet() {
>>    [](auto cctX) { cctX.template should_gather<PriorSet_dpp.get_subsys()>; };
>> }
>> ----------------------------------- 8< -----------------------------------
>>
>> I assume that is intentional and am actually somewhat surprised it was
>> accepted before, but can you please confirm?
> 
> Yes, this seems correct/intentional to me-- no instantiation of the
> template would be valid because it's trying to use a non-constant
> expression (which we now correctly identify as such) as a template
> argument, so this snippet is IFNDR.
> 
> I don't think we have testsuite coverage for this QoI diagnostic, I'll add one.

Incidentally, I wonder about trying to make IFNDR diags in general 
permerrors or default-error pedwarns, but that doesn't need to happen now.

Jason


      reply	other threads:[~2023-05-12 17:13 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-01 19:59 Patrick Palka
2023-05-01 19:59 ` [PATCH 2/2] c++: non-dep init folding and access checking [PR109480] Patrick Palka
2023-05-02 18:35   ` Jason Merrill
2023-05-02 18:34 ` [PATCH 1/2] c++: potentiality of templated memfn call [PR109480] Jason Merrill
2023-05-02 19:35   ` Patrick Palka
2023-05-02 19:53     ` Patrick Palka
2023-05-03 19:55       ` Jason Merrill
2023-05-03 20:50         ` Patrick Palka
2023-05-04 13:56           ` Jason Merrill
2023-05-12 16:12           ` Martin Jambor
2023-05-12 17:02             ` Patrick Palka
2023-05-12 17:13               ` Jason Merrill [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1e148389-a5b1-bb4e-858d-4bd8bb6928f6@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mjambor@suse.cz \
    --cc=ppalka@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).