public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/48119] New: -Wtype-limits should warn when bit masking cannot possibly be true due to type size
@ 2011-03-14 19:23 eteran at alum dot rit.edu
  2011-10-21 12:28 ` [Bug c++/48119] " paolo.carlini at oracle dot com
  2011-10-24  8:08 ` rguenth at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: eteran at alum dot rit.edu @ 2011-03-14 19:23 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48119

           Summary: -Wtype-limits should warn when bit masking cannot
                    possibly be true due to type size
           Product: gcc
           Version: 4.5.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: eteran@alum.rit.edu


I recently encountered a bug in some old code which boiled down to this
situation:

----snip----
#include <stdint.h>
#include <iostream>

int main() {
    uint16_t x = 0xffff;
    ++x;

    // did the value get to big?
    if(x & 0x10000) {
        x = 0xc000;
    }

    // I wanted it to say c000...
    std::cout << std::hex << x << std::endl;
}    
----snip----

Obviously, this was an issue where I needed to use a uint32_t, but mistakenly
used a smaller type, clearly my fault. However, I was surprised that there was
no warning, since the condition is clearly impossible given the uint16_t
datatype.

As far as I know, a conformant compiler is not required to emit a warning for
such code, but it would be a nice improvement to help catch this type of error
in the future.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/48119] -Wtype-limits should warn when bit masking cannot possibly be true due to type size
  2011-03-14 19:23 [Bug c++/48119] New: -Wtype-limits should warn when bit masking cannot possibly be true due to type size eteran at alum dot rit.edu
@ 2011-10-21 12:28 ` paolo.carlini at oracle dot com
  2011-10-24  8:08 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-10-21 12:28 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48119

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu.org

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-10-21 12:28:01 UTC ---
Richard, is this a C++ issue? The C compiler doesn't warn either..


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/48119] -Wtype-limits should warn when bit masking cannot possibly be true due to type size
  2011-03-14 19:23 [Bug c++/48119] New: -Wtype-limits should warn when bit masking cannot possibly be true due to type size eteran at alum dot rit.edu
  2011-10-21 12:28 ` [Bug c++/48119] " paolo.carlini at oracle dot com
@ 2011-10-24  8:08 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-10-24  8:08 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48119

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011-10-24
     Ever Confirmed|0                           |1

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-10-24 08:07:35 UTC ---
Sure it is.

    // did the value get to big?
    if(x & 0x10000) {

should be warned about in the frontend before fold get's a chance to
fold it to false (and yes, we do _not_ want to issue warnings from folders...).

Note that from the description of -Wtype-limits it is not clear if we
want to warn here.  Consider templates where usually a load of this
issues can pop up during instantiation.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-10-24  8:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-14 19:23 [Bug c++/48119] New: -Wtype-limits should warn when bit masking cannot possibly be true due to type size eteran at alum dot rit.edu
2011-10-21 12:28 ` [Bug c++/48119] " paolo.carlini at oracle dot com
2011-10-24  8:08 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).