public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/45918] New: Lack of warning on meaningless unsigned to zero comparison
@ 2010-10-06 21:47 yuri at tsoft dot com
  2010-10-06 23:10 ` [Bug c++/45918] " paolo.carlini at oracle dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: yuri at tsoft dot com @ 2010-10-06 21:47 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Lack of warning on meaningless unsigned to zero
                    comparison
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: yuri@tsoft.com


In this case idx<NUM-1 is always false.
gcc should issue an error: comparison is always false due to the value range
limitations.

--- testcase ---
typedef unsigned size_t;

template<size_t NUM>
struct G {
  void fn();
};

template<size_t NUM>
void G<NUM>::fn() {
    for (size_t idx = 0; idx<NUM-1; idx++) {
    }
}

template struct G<1>;


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

* [Bug c++/45918] Lack of warning on meaningless unsigned to zero comparison
  2010-10-06 21:47 [Bug c++/45918] New: Lack of warning on meaningless unsigned to zero comparison yuri at tsoft dot com
@ 2010-10-06 23:10 ` paolo.carlini at oracle dot com
  2010-10-06 23:16 ` yuri at tsoft dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2010-10-06 23:10 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |paolo.carlini at oracle dot
                   |                            |com

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2010-10-06 23:10:35 UTC ---
I suspect part of this is actually intended, we used to have stronger warnings
at some point in this area, but then people noticed that unavoidably too many
false positives are often produced with templates... Do you have any idea if we
ever warned for this, say, in 4.0,x, 4.1.x?


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

* [Bug c++/45918] Lack of warning on meaningless unsigned to zero comparison
  2010-10-06 21:47 [Bug c++/45918] New: Lack of warning on meaningless unsigned to zero comparison yuri at tsoft dot com
  2010-10-06 23:10 ` [Bug c++/45918] " paolo.carlini at oracle dot com
@ 2010-10-06 23:16 ` yuri at tsoft dot com
  2010-10-06 23:18 ` paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: yuri at tsoft dot com @ 2010-10-06 23:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Yuri <yuri at tsoft dot com> 2010-10-06 23:16:21 UTC ---
No warning in 4.2.1 for example.


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

* [Bug c++/45918] Lack of warning on meaningless unsigned to zero comparison
  2010-10-06 21:47 [Bug c++/45918] New: Lack of warning on meaningless unsigned to zero comparison yuri at tsoft dot com
  2010-10-06 23:10 ` [Bug c++/45918] " paolo.carlini at oracle dot com
  2010-10-06 23:16 ` yuri at tsoft dot com
@ 2010-10-06 23:18 ` paolo.carlini at oracle dot com
  2010-10-07  0:45 ` manu at gcc dot gnu.org
  2011-03-29 17:26 ` redi at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2010-10-06 23:18 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2010-10-06 23:18:20 UTC ---
Let's add Manuel in CC...


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

* [Bug c++/45918] Lack of warning on meaningless unsigned to zero comparison
  2010-10-06 21:47 [Bug c++/45918] New: Lack of warning on meaningless unsigned to zero comparison yuri at tsoft dot com
                   ` (2 preceding siblings ...)
  2010-10-06 23:18 ` paolo.carlini at oracle dot com
@ 2010-10-07  0:45 ` manu at gcc dot gnu.org
  2011-03-29 17:26 ` redi at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu.org @ 2010-10-07  0:45 UTC (permalink / raw)
  To: gcc-bugs

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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2010.10.07 00:45:06
     Ever Confirmed|0                           |1

--- Comment #4 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2010-10-07 00:45:06 UTC ---
manuel@gcc11:~$ test/164733M/build/gcc/cc1plus -Wall -Wextra test.C
 void G<NUM>::fn() void G<NUM>::fn() [with unsigned int NUM = 1u]
test.C:14:17:   instantiated from here
test.C:10:21: warning: comparison of unsigned expression < 0 is always false
[-Wtype-limits]

manuel@gcc11:~$ test/164733M/build/gcc/xgcc -v
Using built-in specs.
COLLECT_GCC=test/164733M/build/gcc/xgcc
Target: x86_64-unknown-linux-gnu
Configured with: /home/manuel/test/src/configure
--prefix=/home/manuel/test/./164733M/install --enable-languages=all,ada
--enable-decimal-float --with-mpc=/opt/cfarm/mpc-0.8
--with-mpfr=/opt/cfarm/mpfr-2.4.1/
Thread model: posix
gcc version 4.6.0 20100929 (experimental) [trunk revision 146344] (GCC)


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

* [Bug c++/45918] Lack of warning on meaningless unsigned to zero comparison
  2010-10-06 21:47 [Bug c++/45918] New: Lack of warning on meaningless unsigned to zero comparison yuri at tsoft dot com
                   ` (3 preceding siblings ...)
  2010-10-07  0:45 ` manu at gcc dot gnu.org
@ 2011-03-29 17:26 ` redi at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2011-03-29 17:26 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |WORKSFORME

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-03-29 17:23:48 UTC ---
works for me, just use -Wtype-limits or -Wextra


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

end of thread, other threads:[~2011-03-29 17:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-06 21:47 [Bug c++/45918] New: Lack of warning on meaningless unsigned to zero comparison yuri at tsoft dot com
2010-10-06 23:10 ` [Bug c++/45918] " paolo.carlini at oracle dot com
2010-10-06 23:16 ` yuri at tsoft dot com
2010-10-06 23:18 ` paolo.carlini at oracle dot com
2010-10-07  0:45 ` manu at gcc dot gnu.org
2011-03-29 17:26 ` redi 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).