OK.
On Fri, Sep 29, 2017 at 4:57 PM, Jakub Jelinek <ja...@redhat.com> wrote: > Hi! > > The casts added for the C++17 direct enum initialization IMNSHO shouldn't > trigger -Wuseless-cast warnings. > > Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for > trunk? > > 2017-09-29 Jakub Jelinek <ja...@redhat.com> > > PR c++/82299 > * decl.c (reshape_init): Suppress warn_useless_cast for direct enum > init. > * typeck.c (convert_for_assignment): Likewise. > > * g++.dg/cpp0x/pr82299.C: New test. > > --- gcc/cp/decl.c.jj 2017-09-29 11:21:55.000000000 +0200 > +++ gcc/cp/decl.c 2017-09-29 15:19:02.549548102 +0200 > @@ -6053,7 +6053,10 @@ reshape_init (tree type, tree init, tsub > tree elt = CONSTRUCTOR_ELT (init, 0)->value; > type = cv_unqualified (type); > if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain)) > - return cp_build_c_cast (type, elt, tf_warning_or_error); > + { > + warning_sentinel w (warn_useless_cast); > + return cp_build_c_cast (type, elt, tf_warning_or_error); > + } > else > return error_mark_node; > } > --- gcc/cp/typeck.c.jj 2017-09-29 09:07:33.000000000 +0200 > +++ gcc/cp/typeck.c 2017-09-29 15:21:17.770926572 +0200 > @@ -8527,7 +8527,10 @@ convert_for_assignment (tree type, tree > { > tree elt = CONSTRUCTOR_ELT (rhs, 0)->value; > if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain)) > - rhs = cp_build_c_cast (type, elt, complain); > + { > + warning_sentinel w (warn_useless_cast); > + rhs = cp_build_c_cast (type, elt, complain); > + } > else > rhs = error_mark_node; > } > --- gcc/testsuite/g++.dg/cpp0x/pr82299.C.jj 2017-09-29 15:24:18.909754416 > +0200 > +++ gcc/testsuite/g++.dg/cpp0x/pr82299.C 2017-09-29 15:29:15.589237065 > +0200 > @@ -0,0 +1,9 @@ > +// PR c++/82299 > +// { dg-do compile { target c++11 } } > +// { dg-options "-Wuseless-cast" } > + > +enum Enum : char { A = 0, B = 1 }; > + > +struct S { > + Enum e { Enum::A }; // { dg-bogus "useless cast to type" } > +}; > > Jakub