public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/8715] '~' operator for unsigned char and conversion to bool
       [not found] <20021126052604.8715.jozef.kosoru@pobox.sk>
@ 2003-06-09 18:44 ` pinskia@physics.uc.edu
  2004-09-24 22:35 ` [Bug c++/8715] " jsm28 at gcc dot gnu dot org
  1 sibling, 0 replies; 11+ messages in thread
From: pinskia@physics.uc.edu @ 2003-06-09 18:44 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


pinskia@physics.uc.edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|major                       |enhancement


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

* [Bug c++/8715] '~' operator for unsigned char and conversion to bool
       [not found] <20021126052604.8715.jozef.kosoru@pobox.sk>
  2003-06-09 18:44 ` [Bug c/8715] '~' operator for unsigned char and conversion to bool pinskia@physics.uc.edu
@ 2004-09-24 22:35 ` jsm28 at gcc dot gnu dot org
  1 sibling, 0 replies; 11+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2004-09-24 22:35 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jsm28 at gcc dot gnu dot org  2004-09-24 22:35 -------
Bogus message only appears for C++, not C.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |c++


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


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

* [Bug c++/8715] '~' operator for unsigned char and conversion to bool
       [not found] <bug-8715-1654@http.gcc.gnu.org/bugzilla/>
                   ` (7 preceding siblings ...)
  2008-08-06 16:20 ` manu at gcc dot gnu dot org
@ 2008-08-06 16:35 ` manu at gcc dot gnu dot org
  8 siblings, 0 replies; 11+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-08-06 16:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from manu at gcc dot gnu dot org  2008-08-06 16:33 -------
Fixed in GCC 4.4.


-- 

manu at gcc dot gnu dot org changed:

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


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


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

* [Bug c++/8715] '~' operator for unsigned char and conversion to bool
       [not found] <bug-8715-1654@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2007-02-16 15:33 ` manu at gcc dot gnu dot org
@ 2008-08-06 16:20 ` manu at gcc dot gnu dot org
  2008-08-06 16:35 ` manu at gcc dot gnu dot org
  8 siblings, 0 replies; 11+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-08-06 16:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from manu at gcc dot gnu dot org  2008-08-06 16:19 -------
Subject: Bug 8715

Author: manu
Date: Wed Aug  6 16:17:41 2008
New Revision: 138814

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=138814
Log:
2008-08-06  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

        PR 8715
        * c-common.c (warn_for_sign_compare): New. Handle separately the
        case that 'constant' is zero.
        * c-typeck.c (build_binary_op): Move code to c-common.c
cp/
        * typeck.c (cp_build_binary_op): Move code to c-common.c.
testsuite/
        * gcc.dg/pr8715.c: New.
        * g++.dg/warn/pr8715.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/warn/pr8715.C
    trunk/gcc/testsuite/gcc.dg/pr8715.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-common.c
    trunk/gcc/c-common.h
    trunk/gcc/c-typeck.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug c++/8715] '~' operator for unsigned char and conversion to bool
       [not found] <bug-8715-1654@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2007-01-26 17:03 ` rearnsha at gcc dot gnu dot org
@ 2007-02-16 15:33 ` manu at gcc dot gnu dot org
  2008-08-06 16:20 ` manu at gcc dot gnu dot org
  2008-08-06 16:35 ` manu at gcc dot gnu dot org
  8 siblings, 0 replies; 11+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-02-16 15:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from manu at gcc dot gnu dot org  2007-02-16 15:33 -------
(In reply to comment #9)
> (In reply to comment #8)
> > I meant that the warning is appropriate but
> > the message is confusing because it is exposing that when doing 
> > 
> > bool x = ~b; 
> > 
> > we actually do 
> > 
> > bool x = (~b != 0);
> > 
> Or, more precisely, 
>   bool x = (~(int) b) != 0;
> 
> > So an appropriate message would say something like:
> > 
> > test.cpp:5: warning: '(bool) ~b' is always true
> 
> > Don't you agree?
> > 
> 
> Yes, that would be nice, but hard to implement.
> 

Isn't any way to tell that "!= 0" was introduced by GCC rather than by the
original source code?


-- 


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


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

* [Bug c++/8715] '~' operator for unsigned char and conversion to bool
       [not found] <bug-8715-1654@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2007-01-26 16:56 ` manu at gcc dot gnu dot org
@ 2007-01-26 17:03 ` rearnsha at gcc dot gnu dot org
  2007-02-16 15:33 ` manu at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2007-01-26 17:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from rearnsha at gcc dot gnu dot org  2007-01-26 17:03 -------
(In reply to comment #8)
> I meant that the warning is appropriate but
> the message is confusing because it is exposing that when doing 
> 
> bool x = ~b; 
> 
> we actually do 
> 
> bool x = (~b != 0);
> 
Or, more precisely, 
  bool x = (~(int) b) != 0;

> So an appropriate message would say something like:
> 
> test.cpp:5: warning: '(bool) ~b' is always true

> Don't you agree?
> 

Yes, that would be nice, but hard to implement.


-- 


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


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

* [Bug c++/8715] '~' operator for unsigned char and conversion to bool
       [not found] <bug-8715-1654@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2007-01-26 16:46 ` rearnsha at gcc dot gnu dot org
@ 2007-01-26 16:56 ` manu at gcc dot gnu dot org
  2007-01-26 17:03 ` rearnsha at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-01-26 16:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from manu at gcc dot gnu dot org  2007-01-26 16:56 -------
(In reply to comment #7)
> (In reply to comment #6)
> > OK. I see now. This seems hard to fix, since it is exposing the current
> > implementation of a conversion to bool.
> > 
> 
> No, it's not the 'current implementation', its the way the C and C++ standards
> say this has to happen.  When arithmetic operators are applied to sub-int sized
> operands they are first converted to int (or unsigned int if they can't be
> represented in int -- which is only the case when you have a machine where
> sizeof(unsigned short) == sizeof(unsigned int), or something similar).
> 

I think I expressed myself badly. I meant that the warning is appropriate but
the message is confusing because it is exposing that when doing 

bool x = ~b; 

we actually do 

bool x = (~b != 0);

So an appropriate message would say something like:

test.cpp:5: warning: '(bool) ~b' is always true


But that is hard to achieve with the current implementation.

Don't you agree?


-- 


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


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

* [Bug c++/8715] '~' operator for unsigned char and conversion to bool
       [not found] <bug-8715-1654@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2007-01-26 16:01 ` manu at gcc dot gnu dot org
@ 2007-01-26 16:46 ` rearnsha at gcc dot gnu dot org
  2007-01-26 16:56 ` manu at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2007-01-26 16:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rearnsha at gcc dot gnu dot org  2007-01-26 16:46 -------
(In reply to comment #6)
> OK. I see now. This seems hard to fix, since it is exposing the current
> implementation of a conversion to bool.
> 

No, it's not the 'current implementation', its the way the C and C++ standards
say this has to happen.  When arithmetic operators are applied to sub-int sized
operands they are first converted to int (or unsigned int if they can't be
represented in int -- which is only the case when you have a machine where
sizeof(unsigned short) == sizeof(unsigned int), or something similar).


-- 


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


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

* [Bug c++/8715] '~' operator for unsigned char and conversion to bool
       [not found] <bug-8715-1654@http.gcc.gnu.org/bugzilla/>
  2006-12-10 19:18 ` manu at gcc dot gnu dot org
  2006-12-10 19:28 ` manu at gcc dot gnu dot org
@ 2007-01-26 16:01 ` manu at gcc dot gnu dot org
  2007-01-26 16:46 ` rearnsha at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-01-26 16:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from manu at gcc dot gnu dot org  2007-01-26 16:00 -------
OK. I see now. This seems hard to fix, since it is exposing the current
implementation of a conversion to bool.


-- 


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


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

* [Bug c++/8715] '~' operator for unsigned char and conversion to bool
       [not found] <bug-8715-1654@http.gcc.gnu.org/bugzilla/>
  2006-12-10 19:18 ` manu at gcc dot gnu dot org
@ 2006-12-10 19:28 ` manu at gcc dot gnu dot org
  2007-01-26 16:01 ` manu at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: manu at gcc dot gnu dot org @ 2006-12-10 19:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from manu at gcc dot gnu dot org  2006-12-10 19:28 -------
(In reply to comment #1)
>  
>  Which is equivalent to writing
>  
>  	unsigned char b = 0x31;
>  	bool x = (~(int) b) != 0;
>  

b being promoted to int is the expected behaviour or is it just what happens
currently? I don't get why it is promoted...

>  A warning would probably seem appropriate. since no value of b can lead to 
>  the x being set to 0.

What is kind of weird since I would expect any value different from 0 to set x
to false.


-- 


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


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

* [Bug c++/8715] '~' operator for unsigned char and conversion to bool
       [not found] <bug-8715-1654@http.gcc.gnu.org/bugzilla/>
@ 2006-12-10 19:18 ` manu at gcc dot gnu dot org
  2006-12-10 19:28 ` manu at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: manu at gcc dot gnu dot org @ 2006-12-10 19:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from manu at gcc dot gnu dot org  2006-12-10 19:17 -------

(In reply to comment #3)
> Bogus message only appears for C++, not C.
> 

Not anymore. I get the warning for C with gcc (GCC) 4.1.2 20060928 (prerelease)
(Ubuntu 4.1.1-13ubuntu5) using -Wsign-compare (which is included in -Wextra).

Is this really a bug?


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org
   Last reconfirmed|2005-12-11 23:05:14         |2006-12-10 19:17:48
               date|                            |


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


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

end of thread, other threads:[~2008-08-06 16:35 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20021126052604.8715.jozef.kosoru@pobox.sk>
2003-06-09 18:44 ` [Bug c/8715] '~' operator for unsigned char and conversion to bool pinskia@physics.uc.edu
2004-09-24 22:35 ` [Bug c++/8715] " jsm28 at gcc dot gnu dot org
     [not found] <bug-8715-1654@http.gcc.gnu.org/bugzilla/>
2006-12-10 19:18 ` manu at gcc dot gnu dot org
2006-12-10 19:28 ` manu at gcc dot gnu dot org
2007-01-26 16:01 ` manu at gcc dot gnu dot org
2007-01-26 16:46 ` rearnsha at gcc dot gnu dot org
2007-01-26 16:56 ` manu at gcc dot gnu dot org
2007-01-26 17:03 ` rearnsha at gcc dot gnu dot org
2007-02-16 15:33 ` manu at gcc dot gnu dot org
2008-08-06 16:20 ` manu at gcc dot gnu dot org
2008-08-06 16:35 ` manu at gcc dot gnu dot 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).