public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/30860] New: Should warn about boolean constant false used in pointer context
@ 2007-02-19 15:27 rguenth at gcc dot gnu dot org
2007-02-19 16:44 ` [Bug c++/30860] " mueller at gcc dot gnu dot org
` (11 more replies)
0 siblings, 12 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-02-19 15:27 UTC (permalink / raw)
To: gcc-bugs
void foo(const char *);
void bar() { foo(false); }
should warn that 'false' is interpreted as NULL pointer constant and as such
is convertible to const char *. (Through false -> (int)0 -> NULL -> (const
char *)0)
As foo(true) is (rightfully) rejected the case above is usually not intended.
See 4.10.
--
Summary: Should warn about boolean constant false used in pointer
context
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: enhancement
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: rguenth at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30860
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/30860] Should warn about boolean constant false used in pointer context
2007-02-19 15:27 [Bug c++/30860] New: Should warn about boolean constant false used in pointer context rguenth at gcc dot gnu dot org
@ 2007-02-19 16:44 ` mueller at gcc dot gnu dot org
2007-02-19 19:01 ` pinskia at gcc dot gnu dot org
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: mueller at gcc dot gnu dot org @ 2007-02-19 16:44 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from mueller at gcc dot gnu dot org 2007-02-19 16:43 -------
manu, is this something already covered by your pending -Wconversion fixes?
--
mueller at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |manu at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30860
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/30860] Should warn about boolean constant false used in pointer context
2007-02-19 15:27 [Bug c++/30860] New: Should warn about boolean constant false used in pointer context rguenth at gcc dot gnu dot org
2007-02-19 16:44 ` [Bug c++/30860] " mueller at gcc dot gnu dot org
@ 2007-02-19 19:01 ` pinskia at gcc dot gnu dot org
2007-02-19 19:14 ` manu at gcc dot gnu dot org
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-02-19 19:01 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2007-02-19 19:01 -------
I don't see why we should warn about a very valid and well defined and will
always work on every compiler. You want to warn about a specific coding style
which I think is wrong in this case (and in the -Weffc++ case).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30860
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/30860] Should warn about boolean constant false used in pointer context
2007-02-19 15:27 [Bug c++/30860] New: Should warn about boolean constant false used in pointer context rguenth at gcc dot gnu dot org
2007-02-19 16:44 ` [Bug c++/30860] " mueller at gcc dot gnu dot org
2007-02-19 19:01 ` pinskia at gcc dot gnu dot org
@ 2007-02-19 19:14 ` manu at gcc dot gnu dot org
2007-02-19 19:48 ` gdr at cs dot tamu dot edu
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-02-19 19:14 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 598 bytes --]
------- Comment #3 from manu at gcc dot gnu dot org 2007-02-19 19:14 -------
(In reply to comment #1)
> manu, is this something already covered by your pending -Wconversion fixes?
>
No, it is not. And I don't think it should be warned by -Wconversion. After
all, no value is changed during the conversion.
On the other hand, we give an error for:
void foo(const char *);
void bar() { foo(1 != 0); }
error: cannot convert âboolâ to âconst char*â for argument â1â to
âvoid foo(const char*)â
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30860
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/30860] Should warn about boolean constant false used in pointer context
2007-02-19 15:27 [Bug c++/30860] New: Should warn about boolean constant false used in pointer context rguenth at gcc dot gnu dot org
` (2 preceding siblings ...)
2007-02-19 19:14 ` manu at gcc dot gnu dot org
@ 2007-02-19 19:48 ` gdr at cs dot tamu dot edu
2007-02-19 19:59 ` gdr at cs dot tamu dot edu
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: gdr at cs dot tamu dot edu @ 2007-02-19 19:48 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from gdr at cs dot tamu dot edu 2007-02-19 19:48 -------
Subject: Re: Should warn about boolean constant false used in pointer context
"pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:
| I don't see why we should warn about a very valid and well defined and will
| always work on every compiler. You want to warn about a specific coding
style
| which I think is wrong in this case (and in the -Weffc++ case).
The code may be well-formed C++, but it certainly is a candidate for
either a conceptual error (or typo) or part of obfuscated code contest.
-- Gaby
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30860
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/30860] Should warn about boolean constant false used in pointer context
2007-02-19 15:27 [Bug c++/30860] New: Should warn about boolean constant false used in pointer context rguenth at gcc dot gnu dot org
` (3 preceding siblings ...)
2007-02-19 19:48 ` gdr at cs dot tamu dot edu
@ 2007-02-19 19:59 ` gdr at cs dot tamu dot edu
2007-02-19 20:21 ` mueller at gcc dot gnu dot org
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: gdr at cs dot tamu dot edu @ 2007-02-19 19:59 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from gdr at cs dot tamu dot edu 2007-02-19 19:59 -------
Subject: Re: Should warn about boolean constant false used in pointer context
"manu at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:
| No, it is not. And I don't think it should be warned by -Wconversion. After
| all, no value is changed during the conversion.
Well, it appears to me that -Wconversion would be appropriate.
-- Gaby
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30860
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/30860] Should warn about boolean constant false used in pointer context
2007-02-19 15:27 [Bug c++/30860] New: Should warn about boolean constant false used in pointer context rguenth at gcc dot gnu dot org
` (4 preceding siblings ...)
2007-02-19 19:59 ` gdr at cs dot tamu dot edu
@ 2007-02-19 20:21 ` mueller at gcc dot gnu dot org
2007-02-19 20:23 ` mueller at gcc dot gnu dot org
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: mueller at gcc dot gnu dot org @ 2007-02-19 20:21 UTC (permalink / raw)
To: gcc-bugs
--
mueller at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2007-02-19 20:21:31
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30860
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/30860] Should warn about boolean constant false used in pointer context
2007-02-19 15:27 [Bug c++/30860] New: Should warn about boolean constant false used in pointer context rguenth at gcc dot gnu dot org
` (5 preceding siblings ...)
2007-02-19 20:21 ` mueller at gcc dot gnu dot org
@ 2007-02-19 20:23 ` mueller at gcc dot gnu dot org
2007-02-19 20:50 ` manu at gcc dot gnu dot org
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: mueller at gcc dot gnu dot org @ 2007-02-19 20:23 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from mueller at gcc dot gnu dot org 2007-02-19 20:23 -------
there is an implicit value conversion, boolean "false" to address "0". I think
that is the definition of -Wconversion, no?
anyway, I'll work on a patch.
--
mueller at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |mueller at gcc dot gnu dot
|dot org |org
Status|NEW |ASSIGNED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30860
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/30860] Should warn about boolean constant false used in pointer context
2007-02-19 15:27 [Bug c++/30860] New: Should warn about boolean constant false used in pointer context rguenth at gcc dot gnu dot org
` (7 preceding siblings ...)
2007-02-19 20:50 ` manu at gcc dot gnu dot org
@ 2007-02-19 20:50 ` gdr at cs dot tamu dot edu
2007-02-20 9:53 ` rguenth at gcc dot gnu dot org
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: gdr at cs dot tamu dot edu @ 2007-02-19 20:50 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from gdr at cs dot tamu dot edu 2007-02-19 20:49 -------
Subject: Re: Should warn about boolean constant false used in pointer context
"mueller at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:
| there is an implicit value conversion, boolean "false" to address "0". I
think
| that is the definition of -Wconversion, no?
Yes.
-- Gaby
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30860
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/30860] Should warn about boolean constant false used in pointer context
2007-02-19 15:27 [Bug c++/30860] New: Should warn about boolean constant false used in pointer context rguenth at gcc dot gnu dot org
` (6 preceding siblings ...)
2007-02-19 20:23 ` mueller at gcc dot gnu dot org
@ 2007-02-19 20:50 ` manu at gcc dot gnu dot org
2007-02-19 20:50 ` gdr at cs dot tamu dot edu
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-02-19 20:50 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from manu at gcc dot gnu dot org 2007-02-19 20:50 -------
(In reply to comment #6)
> there is an implicit value conversion, boolean "false" to address "0". I think
> that is the definition of -Wconversion, no?
>
> anyway, I'll work on a patch.
>
Take a look at http://gcc.gnu.org/ml/gcc-patches/2007-02/txt00054.txt and
particularly at cp/call.c (convert_like_real). I think the warning should go
there with the other NULL warnings.
Cheers,
Manuel.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30860
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/30860] Should warn about boolean constant false used in pointer context
2007-02-19 15:27 [Bug c++/30860] New: Should warn about boolean constant false used in pointer context rguenth at gcc dot gnu dot org
` (8 preceding siblings ...)
2007-02-19 20:50 ` gdr at cs dot tamu dot edu
@ 2007-02-20 9:53 ` rguenth at gcc dot gnu dot org
2007-03-14 23:17 ` mueller at gcc dot gnu dot org
2007-03-14 23:20 ` mueller at gcc dot gnu dot org
11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-02-20 9:53 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from rguenth at gcc dot gnu dot org 2007-02-20 09:53 -------
In reply to comment #4
The case that made me file this bug is changed overload resolution for a
false argument vs. a true argument.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30860
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/30860] Should warn about boolean constant false used in pointer context
2007-02-19 15:27 [Bug c++/30860] New: Should warn about boolean constant false used in pointer context rguenth at gcc dot gnu dot org
` (9 preceding siblings ...)
2007-02-20 9:53 ` rguenth at gcc dot gnu dot org
@ 2007-03-14 23:17 ` mueller at gcc dot gnu dot org
2007-03-14 23:20 ` mueller at gcc dot gnu dot org
11 siblings, 0 replies; 13+ messages in thread
From: mueller at gcc dot gnu dot org @ 2007-03-14 23:17 UTC (permalink / raw)
To: gcc-bugs
------- Comment #10 from mueller at gcc dot gnu dot org 2007-03-14 23:17 -------
Subject: Bug 30860
Author: mueller
Date: Wed Mar 14 23:17:03 2007
New Revision: 122934
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122934
Log:
2007-03-15 Dirk Mueller <dmueller@suse.de>
PR c++/30860
* call.c (convert_conversion_warnings): New..
(convert_like_real): .. factored out from here.
(convert_conversion_warnings): Add warning about
false being converted to NULL in argument passing.
* g++.dg/warn/Wconversion2.C: New.
Added:
trunk/gcc/testsuite/g++.dg/warn/Wconversion2.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/call.c
trunk/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30860
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/30860] Should warn about boolean constant false used in pointer context
2007-02-19 15:27 [Bug c++/30860] New: Should warn about boolean constant false used in pointer context rguenth at gcc dot gnu dot org
` (10 preceding siblings ...)
2007-03-14 23:17 ` mueller at gcc dot gnu dot org
@ 2007-03-14 23:20 ` mueller at gcc dot gnu dot org
11 siblings, 0 replies; 13+ messages in thread
From: mueller at gcc dot gnu dot org @ 2007-03-14 23:20 UTC (permalink / raw)
To: gcc-bugs
------- Comment #11 from mueller at gcc dot gnu dot org 2007-03-14 23:20 -------
Fixed for 4.3.
--
mueller at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.3.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30860
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2007-03-14 23:20 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-19 15:27 [Bug c++/30860] New: Should warn about boolean constant false used in pointer context rguenth at gcc dot gnu dot org
2007-02-19 16:44 ` [Bug c++/30860] " mueller at gcc dot gnu dot org
2007-02-19 19:01 ` pinskia at gcc dot gnu dot org
2007-02-19 19:14 ` manu at gcc dot gnu dot org
2007-02-19 19:48 ` gdr at cs dot tamu dot edu
2007-02-19 19:59 ` gdr at cs dot tamu dot edu
2007-02-19 20:21 ` mueller at gcc dot gnu dot org
2007-02-19 20:23 ` mueller at gcc dot gnu dot org
2007-02-19 20:50 ` manu at gcc dot gnu dot org
2007-02-19 20:50 ` gdr at cs dot tamu dot edu
2007-02-20 9:53 ` rguenth at gcc dot gnu dot org
2007-03-14 23:17 ` mueller at gcc dot gnu dot org
2007-03-14 23:20 ` mueller 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).