public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/19457] New: Warning depends on cached constant
@ 2005-01-15 12:32 reichelt at gcc dot gnu dot org
  2005-01-15 16:49 ` [Bug c++/19457] [4.0 Regression] " pinskia at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2005-01-15 12:32 UTC (permalink / raw)
  To: gcc-bugs

Mainline's C++ frontend warns about the following code snippet:

======================
int i=-1;
unsigned int j= ~0;
======================

warn.cc:2: warning: converting of negative value '-0x000000001' to
'unsigned int'

The strange thing is that the warning disappears if I comment out the
unrelated first line or change the value for "i" to "-2". Looks like
the cached constant determines the type of the new constant.

I'd expect "~0" to be signed and "~0u" to be unsigned, so I think the
warning is correct, but I'm not sure.

But in either case, the warning should not depend on some cached constant.

Btw, what about the constant 0xffffffff? Should a warning appear when
is's assigned to a signed or an unsigned int?

-- 
           Summary: Warning depends on cached constant
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: reichelt at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug c++/19457] [4.0 Regression] Warning depends on cached constant
  2005-01-15 12:32 [Bug c++/19457] New: Warning depends on cached constant reichelt at gcc dot gnu dot org
@ 2005-01-15 16:49 ` pinskia at gcc dot gnu dot org
  2005-01-15 17:07 ` schlie at comcast dot net
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-15 16:49 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-01-15 16:49 -------
Confirmed, I have been wondering where this warning was coming from.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
      Known to fail|                            |4.0.0
      Known to work|                            |3.3.2
   Last reconfirmed|0000-00-00 00:00:00         |2005-01-15 16:49:22
               date|                            |
            Summary|Warning depends on cached   |[4.0 Regression] Warning
                   |constant                    |depends on cached constant
   Target Milestone|---                         |4.0.0


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


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

* [Bug c++/19457] [4.0 Regression] Warning depends on cached constant
  2005-01-15 12:32 [Bug c++/19457] New: Warning depends on cached constant reichelt at gcc dot gnu dot org
  2005-01-15 16:49 ` [Bug c++/19457] [4.0 Regression] " pinskia at gcc dot gnu dot org
@ 2005-01-15 17:07 ` schlie at comcast dot net
  2005-01-15 17:17 ` schlie at comcast dot net
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: schlie at comcast dot net @ 2005-01-15 17:07 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From schlie at comcast dot net  2005-01-15 17:07 -------
(In reply to comment #1)

woudn't one exect that any constant >= 0 to be compatible with signed or unsigned, where
only constants < 0 should be assumed to be only compatible with signed without a cast?



-- 


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


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

* [Bug c++/19457] [4.0 Regression] Warning depends on cached constant
  2005-01-15 12:32 [Bug c++/19457] New: Warning depends on cached constant reichelt at gcc dot gnu dot org
  2005-01-15 16:49 ` [Bug c++/19457] [4.0 Regression] " pinskia at gcc dot gnu dot org
  2005-01-15 17:07 ` schlie at comcast dot net
@ 2005-01-15 17:17 ` schlie at comcast dot net
  2005-01-15 17:36 ` schlie at comcast dot net
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: schlie at comcast dot net @ 2005-01-15 17:17 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From schlie at comcast dot net  2005-01-15 17:17 -------
(In reply to comment #2)

where futher then any constant not explictly negative should be considerd compatible with either
signed or unsigned assignment; thereby 0x80000000 is compatible with either, as the value is not
explicitly negative, although may be interpeted as being so iff assigned to a signed variable of
equal size, but not otherwise; it would seem.


-- 


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


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

* [Bug c++/19457] [4.0 Regression] Warning depends on cached constant
  2005-01-15 12:32 [Bug c++/19457] New: Warning depends on cached constant reichelt at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2005-01-15 17:17 ` schlie at comcast dot net
@ 2005-01-15 17:36 ` schlie at comcast dot net
  2005-01-15 18:10 ` schlie at comcast dot net
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: schlie at comcast dot net @ 2005-01-15 17:36 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From schlie at comcast dot net  2005-01-15 17:36 -------
(In reply to comment #0)

Lasly, (sorry for not collecting all thoughts first), suspect the problem may be that
~ is being considered as being analogous to an arithmetic -, which it shoudn't be;
therefore ~(any constant value >= 0) should be compatible with either signed or unsiged.
although  -(any constant value >= 0) should be compatible with only signed witout a cast.
(as ~ is a bit-wise operation, not a arithmetic one, otherwise one couldn't even specify:
 (unsigned)x = (unsigned)x & 0x3; without a cast, likely generating tons of useless warnings)


-- 


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


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

* [Bug c++/19457] [4.0 Regression] Warning depends on cached constant
  2005-01-15 12:32 [Bug c++/19457] New: Warning depends on cached constant reichelt at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2005-01-15 17:36 ` schlie at comcast dot net
@ 2005-01-15 18:10 ` schlie at comcast dot net
  2005-01-18  1:02 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: schlie at comcast dot net @ 2005-01-15 18:10 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From schlie at comcast dot net  2005-01-15 18:09 -------
(In reply to comment #4)

(again sorry), nor should ~0 be considred equivelent to -1, any more than any explicit
non-signed constant like 0xFFFF for example be (as previously questioned), as such
values only have equivelent representations if the constant's required representation
precision happens to be the same as the targets specifed int type-sizes; therefore
would not be reasonably target portable if treated otherwise.

(assuming for the sake of argument if sizeof(int) = 2, sizeof(long) = 4):

 unsigned long = (assumed signed int compatibe) -1, long == 0xFFFFFFFF
 unsigend long = (assumed unsigned int compatible)~0, long == 0x000FFFF



-- 


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


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

* [Bug c++/19457] [4.0 Regression] Warning depends on cached constant
  2005-01-15 12:32 [Bug c++/19457] New: Warning depends on cached constant reichelt at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2005-01-15 18:10 ` schlie at comcast dot net
@ 2005-01-18  1:02 ` pinskia at gcc dot gnu dot org
  2005-01-29  2:46 ` mmitchel at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-18  1:02 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-01-18 01:02 -------
: Search converges between 2004-08-19-trunk (#518) and 2004-08-20-trunk (#519).

Almost certin this was caused by:
2004-08-19  Nathan Sidwell  <nathan@codesourcery.com>
        
        * doc/invoke.texi (integer-share-limit): Document.
        


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nathan at gcc dot gnu dot
                   |                            |org


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


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

* [Bug c++/19457] [4.0 Regression] Warning depends on cached constant
  2005-01-15 12:32 [Bug c++/19457] New: Warning depends on cached constant reichelt at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2005-01-18  1:02 ` pinskia at gcc dot gnu dot org
@ 2005-01-29  2:46 ` mmitchel at gcc dot gnu dot org
  2005-01-31  1:17 ` cvs-commit at gcc dot gnu dot org
  2005-01-31  1:22 ` mmitchel at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-01-29  2:46 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From mmitchel at gcc dot gnu dot org  2005-01-29 02:46 -------
The C++ front-end has a TREE_NEGATED_INT flag; it is that flag which is getting
cached incorrectly.  The C++ front end is intentionally trying to warn about
conversions from negated integer constants, but not from conversions from things
like "~0".

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |mark at codesourcery dot com
                   |dot org                     |
             Status|NEW                         |ASSIGNED


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


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

* [Bug c++/19457] [4.0 Regression] Warning depends on cached constant
  2005-01-15 12:32 [Bug c++/19457] New: Warning depends on cached constant reichelt at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2005-01-29  2:46 ` mmitchel at gcc dot gnu dot org
@ 2005-01-31  1:17 ` cvs-commit at gcc dot gnu dot org
  2005-01-31  1:22 ` mmitchel at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-01-31  1:17 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-01-31 01:17 -------
Subject: Bug 19457

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2005-01-31 01:17:19

Modified files:
	gcc/cp         : call.c cp-tree.h semantics.c typeck.c 
	                 name-lookup.c ChangeLog 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/warn: conv3.C 

Log message:
	PR c++/19457
	* call.c (convert_like_real): Inline call to
	dubious_conversion_warnings here.
	* cp-tree.h (dubious_conversion_warnings): Remove.
	* semantics.c (finish_unary_op_expr): Copy INTEGER_CSTs before
	setting TREE_NEGATED_INT.
	* typeck.c (dubious_conversion_warnings): Remove.
	
	PR c++/19349
	* name-lookup.c (pushdecl_namespace_level): Avoid accessing free'd
	memory.
	
	PR c++/19457
	* g++.dg/warn/conv3.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&r1=1.527&r2=1.528
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&r1=1.1097&r2=1.1098
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&r1=1.458&r2=1.459
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.609&r2=1.610
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&r1=1.106&r2=1.107
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4601&r2=1.4602
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/warn/conv3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4959&r2=1.4960



-- 


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


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

* [Bug c++/19457] [4.0 Regression] Warning depends on cached constant
  2005-01-15 12:32 [Bug c++/19457] New: Warning depends on cached constant reichelt at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2005-01-31  1:17 ` cvs-commit at gcc dot gnu dot org
@ 2005-01-31  1:22 ` mmitchel at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-01-31  1:22 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From mmitchel at gcc dot gnu dot org  2005-01-31 01:22 -------
Fixed in 4.0.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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


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

end of thread, other threads:[~2005-01-31  1:22 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-15 12:32 [Bug c++/19457] New: Warning depends on cached constant reichelt at gcc dot gnu dot org
2005-01-15 16:49 ` [Bug c++/19457] [4.0 Regression] " pinskia at gcc dot gnu dot org
2005-01-15 17:07 ` schlie at comcast dot net
2005-01-15 17:17 ` schlie at comcast dot net
2005-01-15 17:36 ` schlie at comcast dot net
2005-01-15 18:10 ` schlie at comcast dot net
2005-01-18  1:02 ` pinskia at gcc dot gnu dot org
2005-01-29  2:46 ` mmitchel at gcc dot gnu dot org
2005-01-31  1:17 ` cvs-commit at gcc dot gnu dot org
2005-01-31  1:22 ` mmitchel 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).