On 3/5/21 3:03 PM, Jason Merrill via Gcc-patches 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.
I was going to suggest to continue to issue some warning in contexts
where the result of the conversion cannot be represented in the type
but not otherwise. As in:
template <char N> struct X { };
template <class T> X<sizeof(T)> foo();
void bar ()
{
foo<char[256]>();
}
Does your suggestion have the same effect?
Martin