public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/31755] New: Clarify NULL pointer conversion to other types in initialiser
@ 2007-04-29 13:50 jg at jguk dot org
2009-12-08 23:29 ` [Bug c++/31755] " redi at gcc dot gnu dot org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: jg at jguk dot org @ 2007-04-29 13:50 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1703 bytes --]
Could the warning message below be revised to include a warning that NULL will
evaluate to false or zero?
In addition, is there a way to add the member name which is being initialised
to the warning? The line numbers are not accurate too, so it needs some
inspection to figure out the members concerned.
$ g++ -Wall -o t main.cpp
main.cpp: In constructor A::A():
main.cpp:16: warning: converting to non-pointer type bool from NULL
main.cpp:16: warning: converting to non-pointer type int from NULL
main.cpp:16: warning: converting to non-pointer type unsigned int from NULL
Could it be revised to display something like this?
$ g++ -Wall -o t main.cpp
main.cpp: In constructor A::A():
main.cpp:16: warning: initialization of A::m_bool converts to non-pointer type
bool from NULL
main.cpp:16: warning: initialization of A::m_int converts to non-pointer type
int from NULL
main.cpp:16: warning: initialization of A::m_unit converts to non-pointer type
unsigned int from NULL
Example program:
=====================
// g++ -Wall -o t main.cpp
#include <string.h>
class A
{
public:
A();
bool m_bool;
int m_int;
unsigned int m_uint;
};
A::A()
: m_bool(NULL),
m_int(NULL),
m_uint(NULL)
{
}
int main()
{
}
--
Summary: Clarify NULL pointer conversion to other types in
initialiser
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jg at jguk dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31755
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/31755] Clarify NULL pointer conversion to other types in initialiser
2007-04-29 13:50 [Bug c++/31755] New: Clarify NULL pointer conversion to other types in initialiser jg at jguk dot org
@ 2009-12-08 23:29 ` redi at gcc dot gnu dot org
2010-02-14 12:34 ` jg at jguk dot org
2010-02-14 20:04 ` manu at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu dot org @ 2009-12-08 23:29 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from redi at gcc dot gnu dot org 2009-12-08 23:29 -------
(In reply to comment #0)
> Could the warning message below be revised to include a warning that NULL will
> evaluate to false or zero?
What else would it evaluate to?
N.B. with recent versions of GCC -Wconversion is needed and the conversion to
bool no longer warns
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31755
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/31755] Clarify NULL pointer conversion to other types in initialiser
2007-04-29 13:50 [Bug c++/31755] New: Clarify NULL pointer conversion to other types in initialiser jg at jguk dot org
2009-12-08 23:29 ` [Bug c++/31755] " redi at gcc dot gnu dot org
@ 2010-02-14 12:34 ` jg at jguk dot org
2010-02-14 20:04 ` manu at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: jg at jguk dot org @ 2010-02-14 12:34 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from jg at jguk dot org 2010-02-14 12:34 -------
(In reply to comment #1)
> (In reply to comment #0)
> > Could the warning message below be revised to include a warning that NULL will
> > evaluate to false or zero?
>
> What else would it evaluate to?
In C++ NULL is defined as 0, or 0L. However, as it is a special keyword, I
would like g++ to identify that it is special, and warn when initialising non
pointer types to be NULL.
> N.B. with recent versions of GCC -Wconversion is needed and the conversion to
> bool no longer warns
Ah ok, so it does this already, with the -Wconversion.. I had expected that
would be in -Wall! Can it be added to -Wall?
Jon
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31755
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/31755] Clarify NULL pointer conversion to other types in initialiser
2007-04-29 13:50 [Bug c++/31755] New: Clarify NULL pointer conversion to other types in initialiser jg at jguk dot org
2009-12-08 23:29 ` [Bug c++/31755] " redi at gcc dot gnu dot org
2010-02-14 12:34 ` jg at jguk dot org
@ 2010-02-14 20:04 ` manu at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-02-14 20:04 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from manu at gcc dot gnu dot org 2010-02-14 20:04 -------
(In reply to comment #2)
> In C++ NULL is defined as 0, or 0L. However, as it is a special keyword, I
> would like g++ to identify that it is special, and warn when initialising non
> pointer types to be NULL.
This is on purpose. See PR c++/24745.
> Ah ok, so it does this already, with the -Wconversion.. I had expected that
> would be in -Wall! Can it be added to -Wall?
No, it can't. Wconversion is too noisy at the moment and it warns for perfectly
legitimate code that is difficult to change. I think it is to imprecise even
for -Wextra.
http://gcc.gnu.org/wiki/NewWconversion
Since there is another bug for the other issues you mention, I am closing this
one as INVALID.
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |manu at gcc dot gnu dot org
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31755
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-02-14 20:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-29 13:50 [Bug c++/31755] New: Clarify NULL pointer conversion to other types in initialiser jg at jguk dot org
2009-12-08 23:29 ` [Bug c++/31755] " redi at gcc dot gnu dot org
2010-02-14 12:34 ` jg at jguk dot org
2010-02-14 20:04 ` 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).