This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C/C++ PATCH] Implement -Wshift-overflow (PR c++/55095)


On Mon, 25 May 2015, Marek Polacek wrote:

> +/* Warn if signed left shift overflows.  Note that we don't warn
> +   about left-shifting 1 into the sign bit; cf.
> +   <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3367.html#1457>
> +   for C++ and <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1817.htm>
> +   for C.  LOC is a location of the shift; OP0 and OP1 are the operands.
> +   Return true if an overflow is detected, false otherwise.  */

But for C that was declared not a defect.  See 
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1931.htm#dr_463>.  So 
for C99 and later we *should* consider this an overflow (for the purposes 
of pedwarns-if-pedantic in contexts where an integer constant expression 
is required; maybe -Wshift-overflow=2 for other warnings?).  If then a 
future C standard changes things here (in the list of issues to be 
considered for a future C standard in Standing Document 3, 
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1917.htm>), then, as a 
non-defect change, it should be considered a non-overflow in GCC only for 
future C standard versions as well as C90.

(Although treating something as not an integer constant expression does 
have consequences beyond pedwarns-if-pedantic - a zero derived from that 
expression is not a null pointer constant and that can affect the types of 
conditional expressions - I don't expect any significant breakage of real 
code from that.)

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]