https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49510

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |4.9.0
         Resolution|---                         |FIXED

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Hmm, I don't think we can provide this for compile time warnings.
We do provide runtime error/warnings with -fsanitize=undefined



/app/example.cpp:7:46: runtime error: shift exponent 32 is too large for 32-bit
type 'unsigned int'
/app/example.cpp:8:28: runtime error: shift exponent 32 is too large for 32-bit
type 'int'
/app/example.cpp:11:48: runtime error: shift exponent -1 is negative
/app/example.cpp:12:30: runtime error: shift exponent -1 is negative

If the shifter was that constant we do provide compile time warnings already
(and have for ever, in 4.1.2 for sure):
<source>: In function 'int main()':
<source>:7:46: warning: right shift count >= width of type
[-Wshift-count-overflow]
    7 |   std::cout<<"0xFFFFFFFF>>32 = "<<(0xFFFFFFFF>>32)<<std::endl;
      |                                    ~~~~~~~~~~^~~~
<source>:8:28: warning: left shift count >= width of type
[-Wshift-count-overflow]
    8 |   std::cout<<"1<<32 = "<<(1<<32)<<std::endl;
      |                           ~^~~~
<source>:11:48: warning: right shift count is negative [-Wshift-count-negative]
   11 |   std::cout<<"0xFFFFFFFF>>(-1) = "<<(0xFFFFFFFF>>-1)<<std::endl;
      |                                      ~~~~~~~~~~^~~~
<source>:12:30: warning: left shift count is negative [-Wshift-count-negative]
   12 |   std::cout<<"1<<(-1) = "<<(1<<-1)<<std::endl;
      |                             ~^~~~


-fsanitize=undefined was added in GCC 4.9.0. I don't see how we can warn
without knowing if the code will be executed.

Reply via email to