public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108670] New: Bogus narrowing conversion warning with designated initializers for bitfield in union
@ 2023-02-04  1:18 pokechu022+gccbugzilla at gmail dot com
  0 siblings, 0 replies; only message in thread
From: pokechu022+gccbugzilla at gmail dot com @ 2023-02-04  1:18 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108670
           Summary: Bogus narrowing conversion warning with designated
                    initializers for bitfield in union
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pokechu022+gccbugzilla at gmail dot com
  Target Milestone: ---

This code (https://godbolt.org/z/4YGTfPoY9):

```
union Foo {
    int x : 4;
};
union Bar {
    int y : 4;
};
int foo() {
    Foo foo{.x = 5};
    Bar bar{.y = foo.x};
    return bar.y;
}
```

Yields the following warning:

```
<source>:9:22: warning: narrowing conversion of '(int)foo.Foo::x' from 'int' to
'signed char:4' [-Wnarrowing].
    9 |     Bar bar{.y = foo.x};
      |                  ~~~~^
```

This warning does not make sense since both fields are the same size, and the
field is not a signed char. (A size of 31 will still show a warning with
int:31,  while int:32 gives no warning).

Foo can be either a struct or union. Weirdly, Bar must be a union (and I
couldn't get *any* narrowing conversion warnings to occur with it as a struct,
even if the sizes don't match).

I'm pretty sure this is different from bug 106371 and bug 87292 (though the
latter seems somewhat close). Nor does it match bug 102538. Based on
godbolt.org, this bug exists in the 4.7.1, the first version to support
designated initializers (though they weren't called that then).

This was originally encountered in Dolphin Emulator (see
https://github.com/dolphin-emu/dolphin/pull/11534).

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-04  1:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-04  1:18 [Bug c++/108670] New: Bogus narrowing conversion warning with designated initializers for bitfield in union pokechu022+gccbugzilla at gmail dot com

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