[C/C++ PATCH] Fix -Wshift-overflow with sign bit

Jeff Law law@redhat.com
Wed Aug 12 17:10:00 GMT 2015


On 08/12/2015 09:39 AM, Marek Polacek wrote:
> This patch fixes a defect in -Wshift-overflow.  We should only warn
> about left-shifting 1 into the sign bit when -Wshift-overflow=2.  But
> this doesn't apply only for 1 << 31, but also for 2 << 30, etc.
> In C++14, never warn about this.
>
> Neither existing tests nor documentation require updating, I think.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2015-08-12  Marek Polacek  <polacek@redhat.com>
>
> 	PR c++/55095
> 	* c-common.c (maybe_warn_shift_overflow): Properly handle
> 	left-shifting 1 into the sign bit.
>
> 	* c-c++-common/Wshift-overflow-6.c: New test.
> 	* c-c++-common/Wshift-overflow-7.c: New test.
> 	* g++.dg/cpp1y/left-shift-2.C: New test.
I didn't realize C++14 fixed this bit of lameness.  I'd read that it was 
under consideration when I was looking at Mikael's sext_hwi patch, but 
didn't follow up on the current status.

OK for the trunk.

jeff



More information about the Gcc-patches mailing list