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

            Bug ID: 121969
           Summary: designated aggregate initialization lacks in
                    error-message when inside brace-enclosed initializer
                    list
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: piotr5 at netscape dot net
  Target Milestone: ---

test-case:

```
#include<vector>

struct t{
    int a;
};

t v={.b=1};
```

gives

```
test.cpp:10:10: error: 't' has no non-static data member named 'b'
   10 | t v={.b=1};
      |          ^
```

i.e. the arrow points at end instead of the name it complains about.
so far this is not all that bad, but it gets worse when:

```
std::vector<t> v={{.b=1}};
```

here the error again points to the last closing brace. however, it is not clear
which of the many variables in the struct caused the error, not to mention the
error message itself could be caused by a lot of different unrelated problems
too.
I get:

```
test.cpp:10:25: error: could not convert '{{1}}' from '<brace-enclosed
initializer list>' to 'std::vector<t>'
   10 | std::vector<t> v={{.b=1}};
      |                         ^
      |                         |
      |                         <brace-enclosed initializer list>
```

I can understand if for any custom initializer-list class this were all you
got, but this is the built-in type of initializer-list and cannot be customized
to display the correct error! admittedly, same problem with clang, and I
appreciate how much shorter the error message is in gcc...

so far the only way to debug this is to move out each element of the
initializer list and try to initialize them individually till the typo is
found...

for clarity's sake: I compiled gcc-15.2.0 on gentoo as that's newest possible
production-ready version there.

Reply via email to