public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102538] New: Wrong narrowing conversion checking for initializer with union
@ 2021-09-30  7:04 kito at gcc dot gnu.org
  2021-09-30  7:16 ` [Bug c++/102538] " jakub at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: kito at gcc dot gnu.org @ 2021-09-30  7:04 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102538
           Summary: Wrong narrowing conversion checking for initializer
                    with union
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kito at gcc dot gnu.org
  Target Milestone: ---

How to reproduce:
g++ x.cpp

Testcase:
```
#include <stdint.h>

struct X {
  union {
    uint8_t r8[8];
    uint32_t r32[2];
  };
};

struct ctx {
  X v[1];
};


ctx x = {
  {
     {.r32 = {5,0x33333}},
  }
};
```

Message:
x.cpp:19:1: error: narrowing conversion of '209715' from 'int' to 'uint8_t'
{aka 'unsigned char'} [-Wnarrowing]
   19 | };
      | ^


Work with GCC 11.1 but not work with GCC 11.2 and trunk

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

* [Bug c++/102538] Wrong narrowing conversion checking for initializer with union
  2021-09-30  7:04 [Bug c++/102538] New: Wrong narrowing conversion checking for initializer with union kito at gcc dot gnu.org
@ 2021-09-30  7:16 ` jakub at gcc dot gnu.org
  2021-09-30  7:17 ` [Bug c++/102538] [11/12 Regression] " jakub at gcc dot gnu.org
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-09-30  7:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Started with r12-954-g84fd1b5dff70cd74aee7e8b18f66959d8b8e1ce7 aka PR100489
fix.

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

* [Bug c++/102538] [11/12 Regression] Wrong narrowing conversion checking for initializer with union
  2021-09-30  7:04 [Bug c++/102538] New: Wrong narrowing conversion checking for initializer with union kito at gcc dot gnu.org
  2021-09-30  7:16 ` [Bug c++/102538] " jakub at gcc dot gnu.org
@ 2021-09-30  7:17 ` jakub at gcc dot gnu.org
  2021-09-30  7:20 ` jakub at gcc dot gnu.org
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-09-30  7:17 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-09-30
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jason at gcc dot gnu.org
   Target Milestone|---                         |11.3
             Status|UNCONFIRMED                 |NEW
           Priority|P3                          |P2
            Summary|Wrong narrowing conversion  |[11/12 Regression] Wrong
                   |checking for initializer    |narrowing conversion
                   |with union                  |checking for initializer
                   |                            |with union
     Ever confirmed|0                           |1

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

* [Bug c++/102538] [11/12 Regression] Wrong narrowing conversion checking for initializer with union
  2021-09-30  7:04 [Bug c++/102538] New: Wrong narrowing conversion checking for initializer with union kito at gcc dot gnu.org
  2021-09-30  7:16 ` [Bug c++/102538] " jakub at gcc dot gnu.org
  2021-09-30  7:17 ` [Bug c++/102538] [11/12 Regression] " jakub at gcc dot gnu.org
@ 2021-09-30  7:20 ` jakub at gcc dot gnu.org
  2021-10-01 13:04 ` jakub at gcc dot gnu.org
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-09-30  7:20 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
With -std=gnu++98 it is actually wrong-code (and after all, with newer modes
too if you change 0x33333 to say 6).  With 5, 6 this used to result in
        .type   x, @object
        .size   x, 8
x:
        .long   5
        .long   6
but now it is:
        .type   x, @object
        .size   x, 8
x:
        .byte   5
        .byte   6
        .zero   6

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

* [Bug c++/102538] [11/12 Regression] Wrong narrowing conversion checking for initializer with union
  2021-09-30  7:04 [Bug c++/102538] New: Wrong narrowing conversion checking for initializer with union kito at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-09-30  7:20 ` jakub at gcc dot gnu.org
@ 2021-10-01 13:04 ` jakub at gcc dot gnu.org
  2021-10-01 15:23 ` ppalka at gcc dot gnu.org
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-10-01 13:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Testcase for the wrong-code:
struct X { union { char r8[8]; int r32[2]; }; };
struct Y { X v[1]; };
Y x = { { { .r32 = { 5, 6 } } } };

int
main ()
{
  if (x.v[0].r32[0] != 5 || x.v[0].r32[1] != 6)
    __builtin_abort ();
}

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

* [Bug c++/102538] [11/12 Regression] Wrong narrowing conversion checking for initializer with union
  2021-09-30  7:04 [Bug c++/102538] New: Wrong narrowing conversion checking for initializer with union kito at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-10-01 13:04 ` jakub at gcc dot gnu.org
@ 2021-10-01 15:23 ` ppalka at gcc dot gnu.org
  2021-10-01 15:25 ` jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-10-01 15:23 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Analogous constexpr testcase:

struct X { union { char r8[8]; int r32[2]; }; };
struct Y { X v; };
constexpr Y x = { { .r32 = { 5, 6 } } };
static_assert(x.v.r32[0] == 5 && x.v.r32[1] == 6);

The error is perhaps insightful:

<stdin>:4:31: error: non-constant condition for static assertion
<stdin>:4:31: error: accessing ‘X::<unnamed union>::r32’ member instead of
initialized ‘X::<unnamed union>::r8’ member in constant expression

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

* [Bug c++/102538] [11/12 Regression] Wrong narrowing conversion checking for initializer with union
  2021-09-30  7:04 [Bug c++/102538] New: Wrong narrowing conversion checking for initializer with union kito at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2021-10-01 15:23 ` ppalka at gcc dot gnu.org
@ 2021-10-01 15:25 ` jakub at gcc dot gnu.org
  2021-11-19 17:18 ` ppalka at gcc dot gnu.org
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-10-01 15:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Yeah, the above mentioned reshape* change results in the r32 index of d->cur
being ignored when recursing into the anonymous union.

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

* [Bug c++/102538] [11/12 Regression] Wrong narrowing conversion checking for initializer with union
  2021-09-30  7:04 [Bug c++/102538] New: Wrong narrowing conversion checking for initializer with union kito at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2021-10-01 15:25 ` jakub at gcc dot gnu.org
@ 2021-11-19 17:18 ` ppalka at gcc dot gnu.org
  2022-01-20 17:33 ` ppalka at gcc dot gnu.org
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-11-19 17:18 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

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

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

* [Bug c++/102538] [11/12 Regression] Wrong narrowing conversion checking for initializer with union
  2021-09-30  7:04 [Bug c++/102538] New: Wrong narrowing conversion checking for initializer with union kito at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2021-11-19 17:18 ` ppalka at gcc dot gnu.org
@ 2022-01-20 17:33 ` ppalka at gcc dot gnu.org
  2022-03-04 14:09 ` mpolacek at gcc dot gnu.org
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-01-20 17:33 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

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

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

* [Bug c++/102538] [11/12 Regression] Wrong narrowing conversion checking for initializer with union
  2021-09-30  7:04 [Bug c++/102538] New: Wrong narrowing conversion checking for initializer with union kito at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2022-01-20 17:33 ` ppalka at gcc dot gnu.org
@ 2022-03-04 14:09 ` mpolacek at gcc dot gnu.org
  2022-03-21 20:47 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-03-04 14:09 UTC (permalink / raw)
  To: gcc-bugs

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

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] 14+ messages in thread

* [Bug c++/102538] [11/12 Regression] Wrong narrowing conversion checking for initializer with union
  2021-09-30  7:04 [Bug c++/102538] New: Wrong narrowing conversion checking for initializer with union kito at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2022-03-04 14:09 ` mpolacek at gcc dot gnu.org
@ 2022-03-21 20:47 ` cvs-commit at gcc dot gnu.org
  2022-03-21 21:02 ` [Bug c++/102538] [11 " jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-03-21 20:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:24d51e749570dcb85bd43d3b528f58ad6141de26

commit r12-7741-g24d51e749570dcb85bd43d3b528f58ad6141de26
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Mar 21 09:57:28 2022 -0400

    c++: designated init and aggregate members [PR103337]

    Our C++20 designated initializer handling was broken with members of class
    type; we would find the relevant member and then try to find a member of
    the member with the same name.  Or we would sometimes ignore the designator
    entirely.  The former problem is fixed by the change to reshape_init_class,
    the latter by the change to reshape_init_r.

            PR c++/103337
            PR c++/102740
            PR c++/103299
            PR c++/102538

    gcc/cp/ChangeLog:

            * decl.cc (reshape_init_class): Avoid looking for designator
            after we found it.
            (reshape_init_r): Keep looking for designator.

    gcc/testsuite/ChangeLog:

            * g++.dg/ext/flexary3.C: Remove one error.
            * g++.dg/parse/pr43765.C: Likewise.
            * g++.dg/cpp2a/desig22.C: New test.
            * g++.dg/cpp2a/desig23.C: New test.
            * g++.dg/cpp2a/desig24.C: New test.
            * g++.dg/cpp2a/desig25.C: New test.

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

* [Bug c++/102538] [11 Regression] Wrong narrowing conversion checking for initializer with union
  2021-09-30  7:04 [Bug c++/102538] New: Wrong narrowing conversion checking for initializer with union kito at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2022-03-21 20:47 ` cvs-commit at gcc dot gnu.org
@ 2022-03-21 21:02 ` jason at gcc dot gnu.org
  2022-03-22  5:18 ` cvs-commit at gcc dot gnu.org
  2022-03-26 23:29 ` jason at gcc dot gnu.org
  12 siblings, 0 replies; 14+ messages in thread
From: jason at gcc dot gnu.org @ 2022-03-21 21:02 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|mpolacek at gcc dot gnu.org        |jason at gcc dot gnu.org
            Summary|[11/12 Regression] Wrong    |[11 Regression] Wrong
                   |narrowing conversion        |narrowing conversion
                   |checking for initializer    |checking for initializer
                   |with union                  |with union

--- Comment #7 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for 12 so far.

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

* [Bug c++/102538] [11 Regression] Wrong narrowing conversion checking for initializer with union
  2021-09-30  7:04 [Bug c++/102538] New: Wrong narrowing conversion checking for initializer with union kito at gcc dot gnu.org
                   ` (10 preceding siblings ...)
  2022-03-21 21:02 ` [Bug c++/102538] [11 " jason at gcc dot gnu.org
@ 2022-03-22  5:18 ` cvs-commit at gcc dot gnu.org
  2022-03-26 23:29 ` jason at gcc dot gnu.org
  12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-03-22  5:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:2b2f575e6f27acc0c7ba6a3affc760bf2b96a84b

commit r11-9678-g2b2f575e6f27acc0c7ba6a3affc760bf2b96a84b
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Mar 21 09:57:28 2022 -0400

    c++: designated init and aggregate members [PR103337]

    Our C++20 designated initializer handling was broken with members of class
    type; we would find the relevant member and then try to find a member of
    the member with the same name.  Or we would sometimes ignore the designator
    entirely.  The former problem is fixed by the change to reshape_init_class,
    the latter by the change to reshape_init_r.

            PR c++/103337
            PR c++/102740
            PR c++/103299
            PR c++/102538

    gcc/cp/ChangeLog:

            * decl.c (reshape_init_class): Avoid looking for designator
            after we found it.
            (reshape_init_r): Keep looking for designator.

    gcc/testsuite/ChangeLog:

            * g++.dg/ext/flexary3.C: Remove one error.
            * g++.dg/parse/pr43765.C: Likewise.
            * g++.dg/cpp2a/desig22.C: New test.
            * g++.dg/cpp2a/desig23.C: New test.
            * g++.dg/cpp2a/desig24.C: New test.
            * g++.dg/cpp2a/desig25.C: New test.

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

* [Bug c++/102538] [11 Regression] Wrong narrowing conversion checking for initializer with union
  2021-09-30  7:04 [Bug c++/102538] New: Wrong narrowing conversion checking for initializer with union kito at gcc dot gnu.org
                   ` (11 preceding siblings ...)
  2022-03-22  5:18 ` cvs-commit at gcc dot gnu.org
@ 2022-03-26 23:29 ` jason at gcc dot gnu.org
  12 siblings, 0 replies; 14+ messages in thread
From: jason at gcc dot gnu.org @ 2022-03-26 23:29 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

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

--- Comment #9 from Jason Merrill <jason at gcc dot gnu.org> ---
And 11.3.

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

end of thread, other threads:[~2022-03-26 23:29 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-30  7:04 [Bug c++/102538] New: Wrong narrowing conversion checking for initializer with union kito at gcc dot gnu.org
2021-09-30  7:16 ` [Bug c++/102538] " jakub at gcc dot gnu.org
2021-09-30  7:17 ` [Bug c++/102538] [11/12 Regression] " jakub at gcc dot gnu.org
2021-09-30  7:20 ` jakub at gcc dot gnu.org
2021-10-01 13:04 ` jakub at gcc dot gnu.org
2021-10-01 15:23 ` ppalka at gcc dot gnu.org
2021-10-01 15:25 ` jakub at gcc dot gnu.org
2021-11-19 17:18 ` ppalka at gcc dot gnu.org
2022-01-20 17:33 ` ppalka at gcc dot gnu.org
2022-03-04 14:09 ` mpolacek at gcc dot gnu.org
2022-03-21 20:47 ` cvs-commit at gcc dot gnu.org
2022-03-21 21:02 ` [Bug c++/102538] [11 " jason at gcc dot gnu.org
2022-03-22  5:18 ` cvs-commit at gcc dot gnu.org
2022-03-26 23:29 ` jason 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).