This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C/C++ PATCH] Implement -Wshift-overflow (PR c++/55095)
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>
- Date: Fri, 29 May 2015 20:49:58 +0000
- Subject: Re: [C/C++ PATCH] Implement -Wshift-overflow (PR c++/55095)
- Authentication-results: sourceware.org; auth=none
- References: <20150525194816 dot GX27320 at redhat dot com>
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