C++ PATCH for c++/47504 (bogus overflow error with constexpr)

Jason Merrill jason@redhat.com
Thu Mar 17 22:02:00 GMT 2011


In this testcase, the fix for PR 25125 causes us to rewrite what starts 
as char(int(-1) - int(1)) to char((unsigned char)(-1) - (unsigned 
char)1) and thus char((unsigned char)254).  254 doesn't fit in char, so 
the result has TREE_OVERFLOW set even though the original expression was 
all signed and therefore shouldn't.

One issue here is that the rewriting creates this situation where it 
didn't exist before, so I think the rewriting is wrong.

But it's also the case that both C and C++ distinguish between 
arithmetic overflow (i.e. INT_MAX+1) which has undefined behavior, and 
conversion of a value that doesn't fit in the target type (i.e. 
char(254)), which has implementation-defined behavior.  So we should 
allow the latter in constant expressions, even if it was wrong of the 
compiler to introduce it.

Tested x86_64-pc-linux-gnu, applied to trunk.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 47504.patch
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20110317/8ff790f0/attachment.ksh>


More information about the Gcc-patches mailing list