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.
  • [Bug c++/110231] New: unhelpful... barry.revzin at gmail dot com via Gcc-bugs

Reply via email to