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

Jason Merrill jason@redhat.com
Wed Dec 12 21:32:00 GMT 2018


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
> e.g.:
> 
> 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:
> 
> pr88375.cc:12:1: 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:
> 
> pr88375.cc:10:11: 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)"
>       https://gcc.gnu.org/ml/gcc-patches/2018-12/msg00500.html
> 
> and:
> 
>   "[PATCH 2/2] v2: C++: improvements to binary operator diagnostics (PR
> c++/87504)"
>       https://gcc.gnu.org/ml/gcc-patches/2018-12/msg00236.html
> 
> Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu, on top of
> those patches.
> 
> OK for trunk, if those patches are approved?

OK.

Jason



More information about the Gcc-patches mailing list