public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/23608] New: -Wsign-compare and const propagation
@ 2005-08-29  2:34 br1 at internet dot com dot uy
  2005-08-29  2:57 ` [Bug c++/23608] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: br1 at internet dot com dot uy @ 2005-08-29  2:34 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 899 bytes --]

Compiling

#define FIVE 5

int main()
{
    int i = 5;
    int const ic = 5;

    i < 5u;
    ic < 5u;
    FIVE < 5u; // line 10
}


with -Wsign-compare produces the output

pp.cpp:8: warning: comparison between signed and unsigned integer expressions
pp.cpp:9: warning: comparison between signed and unsigned integer expressions


MSVC only warns on line 8.  G++'s current behaviour is unfortunate because it 
favors #defines over consts.

Regards,
Bruno Martínez

-- 
           Summary: -Wsign-compare and const propagation
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: br1 at internet dot com dot uy
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug c++/23608] -Wsign-compare and const propagation
  2005-08-29  2:34 [Bug c++/23608] New: -Wsign-compare and const propagation br1 at internet dot com dot uy
@ 2005-08-29  2:57 ` pinskia at gcc dot gnu dot org
  2005-08-29 22:50 ` br1 at internet dot com dot uy
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-08-29  2:57 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-08-29 02:34 -------
ic by the C++ standard does not need to propagate its value into ic < 5u so I think the warning is 
warranted.

-- 


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


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

* [Bug c++/23608] -Wsign-compare and const propagation
  2005-08-29  2:34 [Bug c++/23608] New: -Wsign-compare and const propagation br1 at internet dot com dot uy
  2005-08-29  2:57 ` [Bug c++/23608] " pinskia at gcc dot gnu dot org
@ 2005-08-29 22:50 ` br1 at internet dot com dot uy
  2005-08-29 23:01   ` Andrew Pinski
  2005-08-29 23:10 ` pinskia at physics dot uc dot edu
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 8+ messages in thread
From: br1 at internet dot com dot uy @ 2005-08-29 22:50 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From br1 at internet dot com dot uy  2005-08-29 22:24 -------
Could you point me to the section in the standard?  I thought warning were a 
quality of implementation matter.

-- 


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


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

* Re: [Bug c++/23608] -Wsign-compare and const propagation
  2005-08-29 22:50 ` br1 at internet dot com dot uy
@ 2005-08-29 23:01   ` Andrew Pinski
  0 siblings, 0 replies; 8+ messages in thread
From: Andrew Pinski @ 2005-08-29 23:01 UTC (permalink / raw)
  To: gcc-bugzilla; +Cc: gcc-bugs


On Aug 29, 2005, at 6:24 PM, br1 at internet dot com dot uy wrote:

>
> ------- Additional Comments From br1 at internet dot com dot uy  
> 2005-08-29 22:24 -------
> Could you point me to the section in the standard?  I thought warning 
> were a
> quality of implementation matter.

No you misunderstood me.  What I was trying to say the const propagation
does not need to happen.  Since that is the case the warning is still 
valid.

-- Pinski


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

* [Bug c++/23608] -Wsign-compare and const propagation
  2005-08-29  2:34 [Bug c++/23608] New: -Wsign-compare and const propagation br1 at internet dot com dot uy
  2005-08-29  2:57 ` [Bug c++/23608] " pinskia at gcc dot gnu dot org
  2005-08-29 22:50 ` br1 at internet dot com dot uy
@ 2005-08-29 23:10 ` pinskia at physics dot uc dot edu
  2005-08-29 23:19 ` bangerth at dealii dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: pinskia at physics dot uc dot edu @ 2005-08-29 23:10 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at physics dot uc dot edu  2005-08-29 23:01 -------
Subject: Re:  -Wsign-compare and const propagation


On Aug 29, 2005, at 6:24 PM, br1 at internet dot com dot uy wrote:

>
> ------- Additional Comments From br1 at internet dot com dot uy  
> 2005-08-29 22:24 -------
> Could you point me to the section in the standard?  I thought warning 
> were a
> quality of implementation matter.

No you misunderstood me.  What I was trying to say the const propagation
does not need to happen.  Since that is the case the warning is still 
valid.

-- Pinski



-- 


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


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

* [Bug c++/23608] -Wsign-compare and const propagation
  2005-08-29  2:34 [Bug c++/23608] New: -Wsign-compare and const propagation br1 at internet dot com dot uy
                   ` (2 preceding siblings ...)
  2005-08-29 23:10 ` pinskia at physics dot uc dot edu
@ 2005-08-29 23:19 ` bangerth at dealii dot org
  2005-08-30  0:11 ` br1 at internet dot com dot uy
  2005-08-30  0:35 ` gdr at integrable-solutions dot net
  5 siblings, 0 replies; 8+ messages in thread
From: bangerth at dealii dot org @ 2005-08-29 23:19 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2005-08-29 23:10 -------
What Andrew is trying to say is that in C, even variables that are marked  
'const' can be modified. Thus, the compiler can't (naively, i.e. without  
using flow analysis) determine that 'i' or 'ic' have the value 5, and  
therefore warn that there is a comparison between signed and unsigned.  
However, in the last line, the compiler knows the value that is being   
compared to 5u and sees that nothing bad can happen here. It therefore  
does not warn.  
 
In C++, the situation is different, since const variables can't be changed. 
The compiler could therefore be able to determine that the second comparison 
does not warrant a warning. This notwithstanding, the compiler doesn't do  
this right now. 
 
As annoying as this is, I don't consider this a bug. It may be classified 
as an enhancement, though, if someone wants to make this warning contigent 
upon the availability of forward propagation of values. General consensus 
has been, however, not to do this. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Priority|P2                          |P3
   Last reconfirmed|0000-00-00 00:00:00         |2005-08-29 23:10:37
               date|                            |


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


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

* [Bug c++/23608] -Wsign-compare and const propagation
  2005-08-29  2:34 [Bug c++/23608] New: -Wsign-compare and const propagation br1 at internet dot com dot uy
                   ` (3 preceding siblings ...)
  2005-08-29 23:19 ` bangerth at dealii dot org
@ 2005-08-30  0:11 ` br1 at internet dot com dot uy
  2005-08-30  0:35 ` gdr at integrable-solutions dot net
  5 siblings, 0 replies; 8+ messages in thread
From: br1 at internet dot com dot uy @ 2005-08-30  0:11 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From br1 at internet dot com dot uy  2005-08-29 23:23 -------
I don't know much about const in C, just C++.  I just wanted to have this 
request entered in your database, as a possible enhancement, of course.

Regards,
Bruno

-- 


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


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

* [Bug c++/23608] -Wsign-compare and const propagation
  2005-08-29  2:34 [Bug c++/23608] New: -Wsign-compare and const propagation br1 at internet dot com dot uy
                   ` (4 preceding siblings ...)
  2005-08-30  0:11 ` br1 at internet dot com dot uy
@ 2005-08-30  0:35 ` gdr at integrable-solutions dot net
  5 siblings, 0 replies; 8+ messages in thread
From: gdr at integrable-solutions dot net @ 2005-08-30  0:35 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From gdr at integrable-solutions dot net  2005-08-30 00:09 -------
Subject: Re:  -Wsign-compare and const propagation

"bangerth at dealii dot org" <gcc-bugzilla@gcc.gnu.org> writes:

| As annoying as this is, I don't consider this a bug. It may be classified 
| as an enhancement, though, if someone wants to make this warning contigent 
| upon the availability of forward propagation of values. General consensus 
| has been, however, not to do this. 

I agree with Wolfgang's clear analysis.

-- Gaby


-- 


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


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

end of thread, other threads:[~2005-08-30  0:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-29  2:34 [Bug c++/23608] New: -Wsign-compare and const propagation br1 at internet dot com dot uy
2005-08-29  2:57 ` [Bug c++/23608] " pinskia at gcc dot gnu dot org
2005-08-29 22:50 ` br1 at internet dot com dot uy
2005-08-29 23:01   ` Andrew Pinski
2005-08-29 23:10 ` pinskia at physics dot uc dot edu
2005-08-29 23:19 ` bangerth at dealii dot org
2005-08-30  0:11 ` br1 at internet dot com dot uy
2005-08-30  0:35 ` gdr at integrable-solutions dot net

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).