On Wed, Aug 15, 2018 at 11:30 AM, Marek Polacek <pola...@redhat.com> wrote: > We weren't complaining about narrowing when converting to bool because > standard_conversion wasn't setting check_narrowing for the converting to bool > case; it only sets it at the end of the function. Moreover, check_narrowing > wasn't catching real_type -> boolean_type at all, which is wrong; > [dcl.init.list] says that a narrowing conversion is an implicit conversion > from > a floating-point type to an integer type, and bool is an integer type. > > Bootstrapped/regtested on x86_64-linux, ok for trunk? > > 2018-08-14 Marek Polacek <pola...@redhat.com> > > PR c++/65043 > * call.c (standard_conversion): Set check_narrowing. > * typeck2.c (check_narrowing): Use CP_INTEGRAL_TYPE_P rather > than comparing with INTEGER_TYPE. > > * g++.dg/concepts/pr67595.C: Add dg-warning. > * g++.dg/cpp0x/Wnarrowing11.C: New test. > * g++.dg/cpp0x/Wnarrowing12.C: New test. > * g++.dg/cpp0x/rv-cast5.C: Add static_cast. > > diff --git gcc/cp/call.c gcc/cp/call.c > index 62654a9e407..ded279a0f43 100644 > --- gcc/cp/call.c > +++ gcc/cp/call.c > @@ -1387,6 +1387,8 @@ standard_conversion (tree to, tree from, tree expr, > bool c_cast_p, > conv->rank = cr_pbool; > if (NULLPTR_TYPE_P (from) && (flags & LOOKUP_ONLYCONVERTING)) > conv->bad_p = true; > + if (flags & LOOKUP_NO_NARROWING) > + conv->check_narrowing = true; > return conv; > }
Hmm, it might be better to fix this section to properly fall through to the common check_narrowing code below. OK either way. Jason