From: Jason Merrill <jason@redhat.com>
To: Marek Polacek <polacek@redhat.com>,
GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] c++: disallow constinit on functions [PR111173]
Date: Wed, 30 Aug 2023 09:11:09 -0400 [thread overview]
Message-ID: <db56e64a-9090-e205-5503-066a6befc6b7@redhat.com> (raw)
In-Reply-To: <20230829190156.56643-1-polacek@redhat.com>
On 8/29/23 15:01, Marek Polacek wrote:
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
OK.
> -- >8 --
>
> [dcl.constinit]/1: The constinit specifier shall be applied only to a declaration
> of a variable with static or thread storage duration.
>
> and while we detect
>
> constinit int fn();
>
> we weren't detecting
>
> using F = int();
> constinit F f;
>
> PR c++/111173
>
> gcc/cp/ChangeLog:
>
> * decl.cc (grokdeclarator): Disallow constinit on functions.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/cpp2a/constinit19.C: New test.
> ---
> gcc/cp/decl.cc | 3 +++
> gcc/testsuite/g++.dg/cpp2a/constinit19.C | 5 +++++
> 2 files changed, 8 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/cpp2a/constinit19.C
>
> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
> index bea0ee92106..a0e8a24efc0 100644
> --- a/gcc/cp/decl.cc
> +++ b/gcc/cp/decl.cc
> @@ -14639,6 +14639,9 @@ grokdeclarator (const cp_declarator *declarator,
> "storage class %<thread_local%> invalid for "
> "function %qs", name);
> }
> + else if (constinit_p)
> + error_at (declspecs->locations[ds_constinit],
> + "%<constinit%> specifier invalid for function %qs", name);
>
> if (virt_specifiers)
> error ("virt-specifiers in %qs not allowed outside a class "
> diff --git a/gcc/testsuite/g++.dg/cpp2a/constinit19.C b/gcc/testsuite/g++.dg/cpp2a/constinit19.C
> new file mode 100644
> index 00000000000..5be610a18a2
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/constinit19.C
> @@ -0,0 +1,5 @@
> +// PR c++/111173
> +// { dg-do compile { target c++20 } }
> +
> +using Function = int();
> +constinit Function f; // { dg-error ".constinit. specifier invalid for function" }
>
> base-commit: fce74ce2535aa3b7648ba82e7e61eb77d0175546
prev parent reply other threads:[~2023-08-30 13:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-29 19:01 Marek Polacek
2023-08-30 13:11 ` 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=db56e64a-9090-e205-5503-066a6befc6b7@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--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).