public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110231] New: unhelpful diagnostic when constructing through initializer_list
@ 2023-06-12 21:27 barry.revzin at gmail dot com
  2023-06-12 21:32 ` [Bug c++/110231] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: barry.revzin at gmail dot com @ 2023-06-12 21:27 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110231
           Summary: unhelpful diagnostic when constructing through
                    initializer_list
           Product: gcc
           Version: 13.1.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: ---

Consider this example:

#include <initializer_list>

struct Point {
    int first;
    int second;
};

struct Inner {
    Inner(std::initializer_list<Point>);
};

Inner i = {{.x=1, .y=1}, {.x=2, .z=2}};

This is wrong, because I wrote .z=2 instead of .y=2. The error, even on trunk,
is:

<source>:12:38: error: could not convert '{{1, 1}, {2, 2}}' from
'<brace-enclosed initializer list>' to 'Inner'
   12 | Inner i = {{.x=1, .y=1}, {.x=2, .z=2}};
      |                                      ^
      |                                      |
      |                                      <brace-enclosed initializer list>

This gives no indication of the problem is. 

Compare that to:

Point p = {.x=2, .z=2};

which fails with the quite clear message:

<source>:17:22: error: 'Point' has no non-static data member named 'z'
   17 | Point p = {.x=2, .z=2};
      |                      ^

Even the latter could be better - if the members were first and second and I
wrote frist, it just says no member named 'frist' instead of giving a hint, but
pointing to the specific problem is significantly better than... not.

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

* [Bug c++/110231] unhelpful diagnostic when constructing through initializer_list
  2023-06-12 21:27 [Bug c++/110231] New: unhelpful diagnostic when constructing through initializer_list barry.revzin at gmail dot com
@ 2023-06-12 21:32 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-12 21:32 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |90475

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think this is a dup of bug 90475.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90475
[Bug 90475] Diagnostic for designated initializer could be a lot better

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

end of thread, other threads:[~2023-06-12 21:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-12 21:27 [Bug c++/110231] New: unhelpful diagnostic when constructing through initializer_list barry.revzin at gmail dot com
2023-06-12 21:32 ` [Bug c++/110231] " 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).