public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105059] New: Inconsistency between paren- and brace-initialization of a union with anonymous struct
@ 2022-03-25 19:14 barry.revzin at gmail dot com
  2022-12-07  2:38 ` [Bug c++/105059] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: barry.revzin at gmail dot com @ 2022-03-25 19:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105059
           Summary: Inconsistency between paren- and brace-initialization
                    of a union with anonymous struct
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

union U {
    struct {
        int x;
        int y;
    };
    long all;
};

constexpr long parens() {
    U u(42);
    return u.all;
}
static_assert(parens() == 42);

constexpr int braces() {
    U u{42};
    return u.all;
}
static_assert(braces() == 42);

gcc currently considers parens() to be a valid constant expression with value
42 (i.e. U(42) initializes U::long) but considers braces() to be invalid
because of reading the wrong member of the union (i.e. U{42} initializes U::x).

clang currently considers parens() ill-formed by rejecting U(42) entirely (and
then rejects braces() for the same reason as gcc does, because it's u.x that
was initialized). 

The standard doesn't even talk about anonymous structs so it's hard to say what
the "right answer" here is, but it seems to me that either U(42) should do the
same thing as U{42} here or at the very least be ill-formed, but definitely not
do some different valid thing.

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

* [Bug c++/105059] Inconsistency between paren- and brace-initialization of a union with anonymous struct
  2022-03-25 19:14 [Bug c++/105059] New: Inconsistency between paren- and brace-initialization of a union with anonymous struct barry.revzin at gmail dot com
@ 2022-12-07  2:38 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-07  2:38 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|accepts-invalid             |documentation
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2022-12-07

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
With -pedantic:
<source>:2:12: warning: ISO C++ prohibits anonymous structs [-Wpedantic]
    2 |     struct {
      |            ^


So I think this is just a documentation issue of what anonymous struct means
with each of the initializers.

Yes there is an inconsitancy with respect to () vs {} here though.

Confirmed.

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

end of thread, other threads:[~2022-12-07  2:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-25 19:14 [Bug c++/105059] New: Inconsistency between paren- and brace-initialization of a union with anonymous struct barry.revzin at gmail dot com
2022-12-07  2:38 ` [Bug c++/105059] " 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).