public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Marek Polacek <polacek@redhat.com>, Jakub Jelinek <jakub@redhat.com>
Cc: Jonathan Wakely <jwakely@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++, v4: Implement C++23 P2647R1 - Permitting static constexpr variables in constexpr functions
Date: Fri, 18 Nov 2022 11:24:45 -0500	[thread overview]
Message-ID: <529c47ee-b6ff-b5dd-8d4b-1844c46ddbd6@redhat.com> (raw)
In-Reply-To: <Y3eetu4cJoePZT3+@redhat.com>

On 11/18/22 10:03, Marek Polacek wrote:
> On Fri, Nov 18, 2022 at 08:48:32AM +0100, Jakub Jelinek wrote:
>> On Thu, Nov 17, 2022 at 07:15:05PM -0500, Marek Polacek wrote:
>>>> --- gcc/cp/decl.cc.jj	2022-11-16 14:44:43.692339668 +0100
>>>> +++ gcc/cp/decl.cc	2022-11-17 20:53:44.102011594 +0100
>>>> @@ -5600,6 +5600,57 @@ groktypename (cp_decl_specifier_seq *typ
>>>>     return type;
>>>>   }
>>>>   
>>>> +/* For C++17 and older diagnose static or thread_local decls in constexpr
>>>> +   or consteval functions.  For C++20 similarly, except if they are
>>>
>>> In C++17 we don't support consteval so I guess drop the "or consteval "?
>>
>> I just forgot to update the function comment.
>>
>> Anyway, I think:
>>
>>> BTW, I notice that the patch breaks
>>> g++.dg/cpp1y/lambda-generic-func1.C
>>> g++.dg/cpp1z/constexpr-lambda16.C
>>> Maybe they just need dg- tweaks.
>>
>> this is actually a real bug and I'm not sure how to resolve that.
>>
>> We have there:
>>
>> int main()
>> {
>>    [](auto i) { if (i) { int j; static int k; return i + j; } return i; }(0);
>> }
>>
>> and for C++17/20 I presume something (haven't figured out yet what) marks
> 
> Right, that's the C++17 implicit constexpr for lambdas, finish_function:
> 
>    /* Lambda closure members are implicitly constexpr if possible.  */
>    if (cxx_dialect >= cxx17
>        && LAMBDA_TYPE_P (CP_DECL_CONTEXT (fndecl)))
>      DECL_DECLARED_CONSTEXPR_P (fndecl)
>        = ((processing_template_decl
>            || is_valid_constexpr_fn (fndecl, /*complain*/false))
>           && potential_constant_expression (DECL_SAVED_TREE (fndecl)));

Yeah, I guess potential_constant_expression needs to be stricter in a 
lambda. Or perhaps any function that isn't already 
DECL_DECLARED_CONSTEXPR_P?

>> the lambda operator() when still a template as constexpr and then
>> cp_finish_decl -> diagnose_static_in_constexpr pedwarns on it.
>> For the above perhaps we could figure out there is a static int k; in the
>> operator() and don't turn it into constexpr, but what if there is
>> something that would e.g. satisfy decl_maybe_constant_var_p but not
>> decl_constant_var_p when actually instantiated?

I'd expect the above change to potential_c_e to handle that case.

Jason


  parent reply	other threads:[~2022-11-18 16:24 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-11 17:07 [PATCH] c++: " Jakub Jelinek
2022-11-13 11:45 ` [PATCH] c++, v2: " Jakub Jelinek
2022-11-15 23:36   ` Jason Merrill
2022-11-15 23:50     ` Jakub Jelinek
2022-11-16  0:27       ` Jonathan Wakely
2022-11-16  6:19         ` Jakub Jelinek
2022-11-16 13:20           ` Jason Merrill
2022-11-16 14:08             ` Jakub Jelinek
2022-11-16 14:33               ` Jason Merrill
2022-11-16 14:46                 ` Jakub Jelinek
2022-11-16 20:26                   ` Jason Merrill
2022-11-17  9:13                     ` [PATCH] c++, v3: " Jakub Jelinek
2022-11-17 14:42                       ` Jason Merrill
2022-11-17 18:42                         ` Jakub Jelinek
2022-11-17 20:42                           ` [PATCH] c++, v4: " Jakub Jelinek
2022-11-18  0:15                             ` Marek Polacek
2022-11-18  7:48                               ` Jakub Jelinek
2022-11-18 15:03                                 ` Marek Polacek
2022-11-18 15:14                                   ` Jakub Jelinek
2022-11-18 16:24                                   ` Jason Merrill [this message]
2022-11-18 16:34                                     ` Jakub Jelinek
2022-11-18 16:52                                       ` Jason Merrill
2022-11-18  0:28                             ` Jason Merrill
2022-11-18  9:10                               ` [PATCH] c++, v5: " Jakub Jelinek
2022-11-16  0:26     ` [PATCH] c++, v2: " Jonathan Wakely

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=529c47ee-b6ff-b5dd-8d4b-1844c46ddbd6@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jwakely@redhat.com \
    --cc=polacek@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).