public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111173] New: G++ allows constinit functions
@ 2023-08-27 16:16 janschultke at googlemail dot com
  2023-08-27 16:47 ` [Bug c++/111173] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: janschultke at googlemail dot com @ 2023-08-27 16:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111173

            Bug ID: 111173
           Summary: G++ allows constinit functions
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: janschultke at googlemail dot com
  Target Milestone: ---

## Code to Reproduce

using Function = int();
constinit Function f;


## Expected Output (provided by clang trunk)

<source>:2:1: error: constinit can only be used in variable declarations
    2 | constinit Function f;
      | ^
1 error generated.


## Actual Output (https://godbolt.org/z/7rdEhhj1s)

This code compiles with any version of GCC that supports C++20 from what I
could tell. constinit looks to have no effect.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/111173] G++ allows constinit functions
  2023-08-27 16:16 [Bug c++/111173] New: G++ allows constinit functions janschultke at googlemail dot com
@ 2023-08-27 16:47 ` pinskia at gcc dot gnu.org
  2023-08-27 17:09 ` janschultke at googlemail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-27 16:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111173

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-08-27
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
           Keywords|                            |accepts-invalid

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/111173] G++ allows constinit functions
  2023-08-27 16:16 [Bug c++/111173] New: G++ allows constinit functions janschultke at googlemail dot com
  2023-08-27 16:47 ` [Bug c++/111173] " pinskia at gcc dot gnu.org
@ 2023-08-27 17:09 ` janschultke at googlemail dot com
  2023-08-28 15:28 ` mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: janschultke at googlemail dot com @ 2023-08-27 17:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111173

--- Comment #2 from Jan Schultke <janschultke at googlemail dot com> ---
I think the problem is that GCC treats "constinit" exactly like "const" for the
purpose of diagnostics. In https://eel.is/c++draft/dcl.fct#11, it is said that
const applied to functions is ignored.

GCC produces error messages like:
> <source>:1:1: error: 'constinit' on function return type is not allowed
>     1 | constinit void foo();
>       | ^~~~~~~~~

This does not make any sense; "constinit" wouldn't apply to the function return
type in the first place, but to the declarator-id. See
https://eel.is/c++draft/dcl.meaning.general#4

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/111173] G++ allows constinit functions
  2023-08-27 16:16 [Bug c++/111173] New: G++ allows constinit functions janschultke at googlemail dot com
  2023-08-27 16:47 ` [Bug c++/111173] " pinskia at gcc dot gnu.org
  2023-08-27 17:09 ` janschultke at googlemail dot com
@ 2023-08-28 15:28 ` mpolacek at gcc dot gnu.org
  2023-08-30 14:41 ` cvs-commit at gcc dot gnu.org
  2023-08-30 14:46 ` mpolacek at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-08-28 15:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111173

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/111173] G++ allows constinit functions
  2023-08-27 16:16 [Bug c++/111173] New: G++ allows constinit functions janschultke at googlemail dot com
                   ` (2 preceding siblings ...)
  2023-08-28 15:28 ` mpolacek at gcc dot gnu.org
@ 2023-08-30 14:41 ` cvs-commit at gcc dot gnu.org
  2023-08-30 14:46 ` mpolacek at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-08-30 14:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111173

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:c121afc3b6c96a1f229ba0c4a4de6bd4b6be9a53

commit r14-3576-gc121afc3b6c96a1f229ba0c4a4de6bd4b6be9a53
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue Aug 29 13:16:41 2023 -0400

    c++: disallow constinit on functions [PR111173]

    [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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/111173] G++ allows constinit functions
  2023-08-27 16:16 [Bug c++/111173] New: G++ allows constinit functions janschultke at googlemail dot com
                   ` (3 preceding siblings ...)
  2023-08-30 14:41 ` cvs-commit at gcc dot gnu.org
@ 2023-08-30 14:46 ` mpolacek at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-08-30 14:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111173

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-08-30 14:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-27 16:16 [Bug c++/111173] New: G++ allows constinit functions janschultke at googlemail dot com
2023-08-27 16:47 ` [Bug c++/111173] " pinskia at gcc dot gnu.org
2023-08-27 17:09 ` janschultke at googlemail dot com
2023-08-28 15:28 ` mpolacek at gcc dot gnu.org
2023-08-30 14:41 ` cvs-commit at gcc dot gnu.org
2023-08-30 14:46 ` mpolacek at gcc dot gnu.org

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).