This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] C++: better locations for bogus initializations (PR c++/88375)

On 12/11/18 5:55 PM, David Malcolm wrote:
PR c++/88375 reports that errors relating to invalid conversions in
initializations are reported at unhelpfully vague locations, as in

enum struct a : int {
   one, two

struct foo {
   int e1, e2;
   a e3;
} arr[] = {
   { 1, 2, a::one },
   { 3, a::two },
   { 4, 5, a::two }

for which g++ trunk emits the vague: error: cannot convert 'a' to 'int' in initialization
    12 | };
       | ^

with the error at the final closing brace.

This patch uses location information for the initializers, converting the
above to: error: cannot convert 'a' to 'int' in initialization
    10 |   { 3, a::two },
       |        ~~~^~~
       |           |
       |           a

highlighting which subexpression is problematic, and its type.

Ideally we'd also issue a note showing the field decl being initialized,
but that turned out to be more invasive.

This patch relies on:

  "[PATCH 1/2] v3: C++: more location wrapper nodes (PR c++/43064, PR c++/43486)"


  "[PATCH 2/2] v2: C++: improvements to binary operator diagnostics (PR

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu, on top of
those patches.

OK for trunk, if those patches are approved?



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]