On Tue, Mar 23, 2021 at 04:59:53PM -0400, Jason Merrill via Gcc-patches wrote: > On 3/8/21 7:34 PM, Marek Polacek wrote: > > On Fri, Mar 05, 2021 at 05:03:45PM -0500, Jason Merrill wrote: > > > On 3/4/21 9:37 PM, Marek Polacek wrote: > > > > This PR complains that we issue a -Wconversion warning in > > > > > > > > template <int N> struct X {}; > > > > template <class T> X<sizeof(T)> foo(); > > > > > > > > saying "conversion from 'long unsigned int' to 'int' may change value". > > > > While it's not technically wrong, I suspect -Wconversion warnings aren't > > > > all that useful for value-dependent expressions. So this patch disables > > > > them, though I'm open to other ideas. > > > > > > How about suppressing -Wconversion in > > > build_converted_constant_expr_internal? If the size_t value ended up > > > being > > > too large for the int parameter, we would give an error about overflow in > > > a > > > constant expression, not just a warning. > > > > That works for me too. As you say, if we convert to a type that cannot > > represent all the values of the original type, we give a pedantic-error > > warning in check_narrowing. > > > > I've slightly enhanced the test, too. > > > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/10? > > OK.
Thanks, pushed. > I tried Martin's testcase, and get the expected > > wa.C:2:35: error: narrowing conversion of ‘256’ from ‘long unsigned int’ to > ‘char’ [-Wnarrowing] > > Don't you? Huh, I really don't: $ ./cc1plus -quiet q.C -Wall -W -pedantic -Wnarrowing # nothing How can that be? Marek