public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/32061] New: wrong warning wording
@ 2007-05-23 23:45 eyal at eyal dot emu dot id dot au
2007-05-23 23:47 ` [Bug c/32061] " pinskia at gcc dot gnu dot org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: eyal at eyal dot emu dot id dot au @ 2007-05-23 23:45 UTC (permalink / raw)
To: gcc-bugs
This warning is logically incorrect:
logical '&&' with non-zero constant will always evaluate as true
should say '... will have no effect'?
Reproduce with
==============
/* run: gcc -v -save-temps -Wlogical-op -c xx.c
*/
#define FORCE 1
#define FLAG 1
static int func (int resp, int flags)
{
return (resp && (FORCE || (FLAG & flags)));
}
output
======
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /usr/local/src/gcc/src/gcc-current/configure
--srcdir=/usr/local/src/gcc/src/gcc-current --prefix=/usr/local/gcc-current
--enable-languages=c,c++ --with-mpfr=/usr/local/mpfr --with-gmp=/usr/local/gmp
Thread model: posix
gcc version 4.3.0 20070518 (experimental)
/data2/usr/local/gcc-current-20070519-083055/bin/../libexec/gcc/i686-pc-linux-gnu/4.3.0/cc1
-E -quiet -v -iprefix
/data2/usr/local/gcc-current-20070519-083055/bin/../lib/gcc/i686-pc-linux-gnu/4.3.0/
xx.c -mtune=generic -Wlogical-op -fpch-preprocess -o xx.i
ignoring nonexistent directory
"/data2/usr/local/gcc-current-20070519-083055/bin/../lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../i686-pc-linux-gnu/include"
ignoring duplicate directory
"/data2/usr/local/gcc-current-20070519-083055/bin/../lib/gcc/../../lib/gcc/i686-pc-linux-gnu/4.3.0/include"
ignoring duplicate directory
"/data2/usr/local/gcc-current-20070519-083055/bin/../lib/gcc/../../lib/gcc/i686-pc-linux-gnu/4.3.0/include-fixed"
ignoring nonexistent directory
"/data2/usr/local/gcc-current-20070519-083055/bin/../lib/gcc/../../lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/data2/usr/local/gcc-current-20070519-083055/bin/../lib/gcc/i686-pc-linux-gnu/4.3.0/include
/data2/usr/local/gcc-current-20070519-083055/bin/../lib/gcc/i686-pc-linux-gnu/4.3.0/include-fixed
/usr/local/include
/data2/usr/local/gcc-current-20070519-083055/bin/../lib/gcc/../../include
/usr/include
End of search list.
/data2/usr/local/gcc-current-20070519-083055/bin/../libexec/gcc/i686-pc-linux-gnu/4.3.0/cc1
-fpreprocessed xx.i -quiet -dumpbase xx.c -mtune=generic -auxbase xx
-Wlogical-op -version -o xx.s
GNU C version 4.3.0 20070518 (experimental) (i686-pc-linux-gnu)
compiled by GNU C version 4.3.0 20070518 (experimental), GMP version
4.2.1, MPFR version 2.2.1.
warning: GMP header version 4.2.1 differs from library version 4.1.4.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 128b6cbfc01a7daaa897672777a1e4cb
xx.c: In function 'func':
xx.c:7: warning: logical '&&' with non-zero constant will always evaluate as
true
as -V -Qy -o xx.o xx.s
GNU assembler version 2.15 (i386-linux) using BFD version 2.15
--
Summary: wrong warning wording
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: eyal at eyal dot emu dot id dot au
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32061
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/32061] wrong warning wording
2007-05-23 23:45 [Bug c/32061] New: wrong warning wording eyal at eyal dot emu dot id dot au
@ 2007-05-23 23:47 ` pinskia at gcc dot gnu dot org
2007-05-24 0:00 ` eyal at eyal dot emu dot id dot au
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-05-23 23:47 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2007-05-24 00:47 -------
I don't see the problem because
"xx.c:7: warning: logical '&&' with non-zero constant will always evaluate as
true"
means the non-zero constant will evaluate as true and not the logical will
evaluate as true.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32061
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/32061] wrong warning wording
2007-05-23 23:45 [Bug c/32061] New: wrong warning wording eyal at eyal dot emu dot id dot au
2007-05-23 23:47 ` [Bug c/32061] " pinskia at gcc dot gnu dot org
@ 2007-05-24 0:00 ` eyal at eyal dot emu dot id dot au
2009-02-11 23:04 ` [Bug c/32061] (Wlogical-op) wording of warning of constant logicials need improvement manu at gcc dot gnu dot org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: eyal at eyal dot emu dot id dot au @ 2007-05-24 0:00 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from eyal at eyal dot emu dot id dot au 2007-05-24 01:00 -------
(In reply to comment #1)
> I don't see the problem because
> "xx.c:7: warning: logical '&&' with non-zero constant will always evaluate as
> true"
> means the non-zero constant will evaluate as true and not the logical will
> evaluate as true.
>
(In reply to comment #1)
> I don't see the problem because
> "xx.c:7: warning: logical '&&' with non-zero constant will always evaluate as
> true"
> means the non-zero constant will evaluate as true and not the logical will
> evaluate as true.
>
But it says 'logical... will always evaluate as true' which clearly refers to
the result of the logical operator, not to one of its arguments.
BTW, why no warning for this?
resp == 0 && 0
Naturally, all the above constants will hide behind some macros which could
indicate a real error, hence the value of the warning.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32061
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/32061] (Wlogical-op) wording of warning of constant logicials need improvement
2007-05-23 23:45 [Bug c/32061] New: wrong warning wording eyal at eyal dot emu dot id dot au
2007-05-23 23:47 ` [Bug c/32061] " pinskia at gcc dot gnu dot org
2007-05-24 0:00 ` eyal at eyal dot emu dot id dot au
@ 2009-02-11 23:04 ` manu at gcc dot gnu dot org
2009-02-12 8:29 ` eyal at eyal dot emu dot id dot au
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-02-11 23:04 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from manu at gcc dot gnu dot org 2009-02-11 23:04 -------
Confirmed. I have a patch for this for 4.5.
The new wording will say:
warning: logical 'or' applied to non-boolean constant.
Are you satisfied with this?
>
> BTW, why no warning for this?
> resp == 0 && 0
> Naturally, all the above constants will hide behind some macros which could
> indicate a real error, hence the value of the warning.
Warning for (x && 0) or (x && 1) would produce hundreds of false positives. We
shouldn't warn about your testcase either.
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |manu at gcc dot gnu dot org
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2009-02-11 23:04:41
date| |
Summary|wording of warning of |(Wlogical-op) wording of
|constant logicials need |warning of constant
|improvement |logicials need improvement
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32061
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/32061] (Wlogical-op) wording of warning of constant logicials need improvement
2007-05-23 23:45 [Bug c/32061] New: wrong warning wording eyal at eyal dot emu dot id dot au
` (2 preceding siblings ...)
2009-02-11 23:04 ` [Bug c/32061] (Wlogical-op) wording of warning of constant logicials need improvement manu at gcc dot gnu dot org
@ 2009-02-12 8:29 ` eyal at eyal dot emu dot id dot au
2009-02-18 13:13 ` manu at gcc dot gnu dot org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: eyal at eyal dot emu dot id dot au @ 2009-02-12 8:29 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from eyal at eyal dot emu dot id dot au 2009-02-12 08:28 -------
(In reply to comment #3)
> Confirmed. I have a patch for this for 4.5.
>
> The new wording will say:
>
> warning: logical 'or' applied to non-boolean constant.
>
> Are you satisfied with this?
Great, thanks.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32061
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/32061] (Wlogical-op) wording of warning of constant logicials need improvement
2007-05-23 23:45 [Bug c/32061] New: wrong warning wording eyal at eyal dot emu dot id dot au
` (3 preceding siblings ...)
2009-02-12 8:29 ` eyal at eyal dot emu dot id dot au
@ 2009-02-18 13:13 ` manu at gcc dot gnu dot org
2009-04-19 11:05 ` manu at gcc dot gnu dot org
2009-04-19 11:07 ` manu at gcc dot gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-02-18 13:13 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from manu at gcc dot gnu dot org 2009-02-18 13:13 -------
Patch submitted: http://gcc.gnu.org/ml/gcc-patches/2009-02/msg00824.html
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
URL| |http://gcc.gnu.org/ml/gcc-
| |patches/2009-
| |02/msg00824.html
Keywords| |patch
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32061
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/32061] (Wlogical-op) wording of warning of constant logicials need improvement
2007-05-23 23:45 [Bug c/32061] New: wrong warning wording eyal at eyal dot emu dot id dot au
` (4 preceding siblings ...)
2009-02-18 13:13 ` manu at gcc dot gnu dot org
@ 2009-04-19 11:05 ` manu at gcc dot gnu dot org
2009-04-19 11:07 ` manu at gcc dot gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-04-19 11:05 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1599 bytes --]
------- Comment #6 from manu at gcc dot gnu dot org 2009-04-19 11:04 -------
Subject: Bug 32061
Author: manu
Date: Sun Apr 19 11:04:13 2009
New Revision: 146344
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=146344
Log:
2009-04-19 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR c/32061
PR c++/36954
* doc/invoke.texi: Add -Wlogical-op to -Wextra.
* common.opt (Wlogical-op): Move from here...
* c.opt (Wlogical-op): ... to here.
* c-typeck.c (parser_build_binary_op): Update call to
warn_logical_operator.
* c-opts.c (c_common_post_options): Enable warn_logical_op with
extra_warnings.
* c-common.c (warn_logical_op): Update.
* c-common.h (warn_logical_op): Update declaration.
cp/
* call.c (build_new_op): Save the original codes of operands
before folding.
testsuite/
* gcc.dg/pr32061.c: New.
* gcc.dg/Wlogical-op-1.c: Update.
* g++.dg/warn/Wlogical-op-1.C: Update.
* g++.dg/warn/pr36954.C: New.
Added:
trunk/gcc/testsuite/g++.dg/warn/pr36954.C
trunk/gcc/testsuite/gcc.dg/pr32061.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/c-common.c
trunk/gcc/c-common.h
trunk/gcc/c-opts.c
trunk/gcc/c-typeck.c
trunk/gcc/c.opt
trunk/gcc/common.opt
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/call.c
trunk/gcc/doc/invoke.texi
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/g++.dg/warn/Wlogical-op-1.C
trunk/gcc/testsuite/gcc.dg/Wlogical-op-1.c
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32061
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c/32061] (Wlogical-op) wording of warning of constant logicials need improvement
2007-05-23 23:45 [Bug c/32061] New: wrong warning wording eyal at eyal dot emu dot id dot au
` (5 preceding siblings ...)
2009-04-19 11:05 ` manu at gcc dot gnu dot org
@ 2009-04-19 11:07 ` manu at gcc dot gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2009-04-19 11:07 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from manu at gcc dot gnu dot org 2009-04-19 11:06 -------
FIXED in GCC 4.5
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32061
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-04-19 11:07 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-23 23:45 [Bug c/32061] New: wrong warning wording eyal at eyal dot emu dot id dot au
2007-05-23 23:47 ` [Bug c/32061] " pinskia at gcc dot gnu dot org
2007-05-24 0:00 ` eyal at eyal dot emu dot id dot au
2009-02-11 23:04 ` [Bug c/32061] (Wlogical-op) wording of warning of constant logicials need improvement manu at gcc dot gnu dot org
2009-02-12 8:29 ` eyal at eyal dot emu dot id dot au
2009-02-18 13:13 ` manu at gcc dot gnu dot org
2009-04-19 11:05 ` manu at gcc dot gnu dot org
2009-04-19 11:07 ` 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).