public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99625] New: GCC does not detect narrowing in aggregate initialization
@ 2021-03-17 13:42 dangelog at gmail dot com
  2021-07-22 14:26 ` [Bug c++/99625] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: dangelog at gmail dot com @ 2021-03-17 13:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99625
           Summary: GCC does not detect narrowing in aggregate
                    initialization
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dangelog at gmail dot com
  Target Milestone: ---

Testcase:

    extern long double l;

    struct S {
        S(int) {}
    };

    S s[] = { l };


This is supposed to be ill-formed because of narrowing. GCC does not reject the
code, nor it warns (as it usually does for narrowing).

The relevant rule is in [dcl.init.aggr]:

https://eel.is/c++draft/dcl.init.aggr#4.2.sentence-2

> Otherwise, the element is copy-initialized from the corresponding initializer-clause or is initialized with the brace-or-equal-initializer of the corresponding designated-initializer-clause.
> If that initializer is of the form assignment-expression or = assignment-expression and a narrowing conversion ([dcl.init.list]) is required to convert the expression, the program is ill-formed.


That rule has been changed in C++20 with designated initializers, but the same
one was also there for C++17 and before, e.g.
https://timsong-cpp.github.io/cppwp/n4659/dcl.init.aggr#3


For comparison, Clang accepts with no warnings, but MSVC warns about narrowing.

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

* [Bug c++/99625] GCC does not detect narrowing in aggregate initialization
  2021-03-17 13:42 [Bug c++/99625] New: GCC does not detect narrowing in aggregate initialization dangelog at gmail dot com
@ 2021-07-22 14:26 ` redi at gcc dot gnu.org
  2021-07-22 14:27 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2021-07-22 14:26 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-07-22
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Confirmed, this should be a -Wnarrowing warning.

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

* [Bug c++/99625] GCC does not detect narrowing in aggregate initialization
  2021-03-17 13:42 [Bug c++/99625] New: GCC does not detect narrowing in aggregate initialization dangelog at gmail dot com
  2021-07-22 14:26 ` [Bug c++/99625] " redi at gcc dot gnu.org
@ 2021-07-22 14:27 ` mpolacek at gcc dot gnu.org
  2022-11-15 14:39 ` dangelog at gmail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-07-22 14:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I've dealt with this in the past -- mine.

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

* [Bug c++/99625] GCC does not detect narrowing in aggregate initialization
  2021-03-17 13:42 [Bug c++/99625] New: GCC does not detect narrowing in aggregate initialization dangelog at gmail dot com
  2021-07-22 14:26 ` [Bug c++/99625] " redi at gcc dot gnu.org
  2021-07-22 14:27 ` mpolacek at gcc dot gnu.org
@ 2022-11-15 14:39 ` dangelog at gmail dot com
  2022-11-15 14:45 ` mpolacek at gcc dot gnu.org
  2022-11-15 14:51 ` dangelog at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: dangelog at gmail dot com @ 2022-11-15 14:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Giuseppe D'Angelo <dangelog at gmail dot com> ---
Hi,

Sorry to ping, but some time has gone by -- I guess this fell through the
cracks?

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

* [Bug c++/99625] GCC does not detect narrowing in aggregate initialization
  2021-03-17 13:42 [Bug c++/99625] New: GCC does not detect narrowing in aggregate initialization dangelog at gmail dot com
                   ` (2 preceding siblings ...)
  2022-11-15 14:39 ` dangelog at gmail dot com
@ 2022-11-15 14:45 ` mpolacek at gcc dot gnu.org
  2022-11-15 14:51 ` dangelog at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-11-15 14:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Giuseppe D'Angelo from comment #3)
> Hi,
> 
> Sorry to ping, but some time has gone by -- I guess this fell through the
> cracks?

Yes, it did.  Sorry.  :-(

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

* [Bug c++/99625] GCC does not detect narrowing in aggregate initialization
  2021-03-17 13:42 [Bug c++/99625] New: GCC does not detect narrowing in aggregate initialization dangelog at gmail dot com
                   ` (3 preceding siblings ...)
  2022-11-15 14:45 ` mpolacek at gcc dot gnu.org
@ 2022-11-15 14:51 ` dangelog at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: dangelog at gmail dot com @ 2022-11-15 14:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Giuseppe D'Angelo <dangelog at gmail dot com> ---
No problem, thanks for working on GCC :)

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

end of thread, other threads:[~2022-11-15 14:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-17 13:42 [Bug c++/99625] New: GCC does not detect narrowing in aggregate initialization dangelog at gmail dot com
2021-07-22 14:26 ` [Bug c++/99625] " redi at gcc dot gnu.org
2021-07-22 14:27 ` mpolacek at gcc dot gnu.org
2022-11-15 14:39 ` dangelog at gmail dot com
2022-11-15 14:45 ` mpolacek at gcc dot gnu.org
2022-11-15 14:51 ` dangelog 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).