public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114067] New: GCC gives wrong diagnostic in the definition of a static data member of same class type
@ 2024-02-23  4:23 jlame646 at gmail dot com
  2024-02-23  4:25 ` [Bug c++/114067] " jlame646 at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: jlame646 at gmail dot com @ 2024-02-23  4:23 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114067
           Summary: GCC gives wrong diagnostic in the definition of a
                    static data member of same class type
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jlame646 at gmail dot com
  Target Milestone: ---

The following program produces wrong diagnostic with gcc and clang:

```
struct A{
    int x;
    static const A a{1};
};
```
GCC says `in-class initialization of static data member 'const A A::a' of
incomplete type`.

While the actual problem is not that `A` is incomplete but that it is not an
integral or enumeration type. 

Only msvc gives correct diagnostic saying:

```
 error C2864: 'A::a': a static data member with an in-class initializer must
have non-volatile const integral type or be specified as 'inline'
```

So I think gcc should say something similar to msvc instead of saying that `A`
being incomplete is the problem.

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

* [Bug c++/114067] GCC gives wrong diagnostic in the definition of a static data member of same class type
  2024-02-23  4:23 [Bug c++/114067] New: GCC gives wrong diagnostic in the definition of a static data member of same class type jlame646 at gmail dot com
@ 2024-02-23  4:25 ` jlame646 at gmail dot com
  2024-02-23  4:31 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: jlame646 at gmail dot com @ 2024-02-23  4:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jason Liam <jlame646 at gmail dot com> ---
That is, even if the type of `a` was complete the program would've been
ill-formed. So saying only that `A` is incomplete is the problem doesn't seem
right.

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

* [Bug c++/114067] GCC gives wrong diagnostic in the definition of a static data member of same class type
  2024-02-23  4:23 [Bug c++/114067] New: GCC gives wrong diagnostic in the definition of a static data member of same class type jlame646 at gmail dot com
  2024-02-23  4:25 ` [Bug c++/114067] " jlame646 at gmail dot com
@ 2024-02-23  4:31 ` pinskia at gcc dot gnu.org
  2024-02-23  8:04 ` jlame646 at gmail dot com
  2024-02-23  8:09 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-23  4:31 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic

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

Actually A at that point is incomplete type.

Note MSVC gives really bad diagnostic for:
```
struct A{
    int x;
    static constexpr const A a{1};
};
```
says undefined type A rather than incomplete type.

Anyways GCC's check for incomplete type happens before the other checks.
Plus GCC allows it with -fpermissive ....

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

* [Bug c++/114067] GCC gives wrong diagnostic in the definition of a static data member of same class type
  2024-02-23  4:23 [Bug c++/114067] New: GCC gives wrong diagnostic in the definition of a static data member of same class type jlame646 at gmail dot com
  2024-02-23  4:25 ` [Bug c++/114067] " jlame646 at gmail dot com
  2024-02-23  4:31 ` pinskia at gcc dot gnu.org
@ 2024-02-23  8:04 ` jlame646 at gmail dot com
  2024-02-23  8:09 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jlame646 at gmail dot com @ 2024-02-23  8:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jason Liam <jlame646 at gmail dot com> ---
(In reply to Andrew Pinski from comment #2)
> Actually A at that point is incomplete type.

Yes, it is incomplete at that point but that is not the reason for the program
to be ill-formed. The reason is that `A` is a class-type and not an
integral/enumeration type.

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

* [Bug c++/114067] GCC gives wrong diagnostic in the definition of a static data member of same class type
  2024-02-23  4:23 [Bug c++/114067] New: GCC gives wrong diagnostic in the definition of a static data member of same class type jlame646 at gmail dot com
                   ` (2 preceding siblings ...)
  2024-02-23  8:04 ` jlame646 at gmail dot com
@ 2024-02-23  8:09 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-23  8:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jason Liam from comment #3)
> (In reply to Andrew Pinski from comment #2)
> > Actually A at that point is incomplete type.
> 
> Yes, it is incomplete at that point but that is not the reason for the
> program to be ill-formed. The reason is that `A` is a class-type and not an
> integral/enumeration type.

As I mentioned there is a extension which allows it be accepted (only with
-fpermissive) if it was complete. And the checking for it being complete
happens before that other check. Now I fully looked into how fix this so the
diagnostic for the completeness happens after allowing the extension because it
seems like the check for completeness happens way before in a different
function.

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

end of thread, other threads:[~2024-02-23  8:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-23  4:23 [Bug c++/114067] New: GCC gives wrong diagnostic in the definition of a static data member of same class type jlame646 at gmail dot com
2024-02-23  4:25 ` [Bug c++/114067] " jlame646 at gmail dot com
2024-02-23  4:31 ` pinskia at gcc dot gnu.org
2024-02-23  8:04 ` jlame646 at gmail dot com
2024-02-23  8:09 ` pinskia 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).