------- Comment #16 from mdorey at bluearc dot com  2009-12-22 18:12 -------
(In reply to comment #15)
> you missed the part where I said "but 0 is still a valid definition of NULL"

(I didn't quote it but I did explicitly agree with it.)

> You claimed in comment 12 that the compiler will be *required* to reject
> conversions from NULL to int, which is patently not true if 0 or 0L is a valid
> definition of NULL.

You're right.  My citations in comment #9 refer to nullptr, not NULL, and my
examples in comment #12 refer to __null, not NULL.  In my prose for comment
#12, however, I was wrongly assuming that NULL would be required to be nullptr
in the new Standard.  Having read more of the current draft in response to your
post of yesterday, I agree that such a change is not required.

This PR, then, is not an accepts-invalid.  It's an enhancement request to
reinstate one of the warnings, about accidentally inappropriate use of NULL,
that became disabled by default between gcc-4.1 and gcc-4.2.

Three warnings about NULL conversions were disabled by default in 4.2.  Per
comment #1, this was because two of the warnings rejected code which ought to
be allowed.  Per comment #9, that code which ought to be allowed is a valid use
of nullptr.  However, 4.3 seems to have removed the two problematic warnings,
even when -Wconversion is used.  That suggests that this PR could now be
addressed, without regressing the two PRs cited in comment #1, by enabling the
warning about this particular conversion by default, as it was in 4.1.  That
would address the OP's example and discourage code that wouldn't compile with
#define NULL nullptr.

Evidence for the new claim in the above paragraph:

mart...@ithaki:~/playpen$ g++-4.1 -c -pedantic null-conversion.cpp 
null-conversion.cpp: In function ‘void test()’:
null-conversion.cpp:2: warning: converting to non-pointer type ‘bool’ from NULL
null-conversion.cpp:3: warning: converting to non-pointer type ‘int’ from NULL
null-conversion.cpp:4: warning: converting to non-pointer type ‘int’ from NULL
mart...@ithaki:~/playpen$ 
mart...@duezer:~/playpen$ g++-4.2 -c -pedantic null-conversion.cpp 
mart...@duezer:~/playpen$ g++-4.2 -Wconversion -c -pedantic null-conversion.cpp

null-conversion.cpp: In function ‘void test()’:
null-conversion.cpp:2: warning: converting to non-pointer type ‘bool’ from NULL
null-conversion.cpp:3: warning: converting to non-pointer type ‘int’ from NULL
null-conversion.cpp:4: warning: converting to non-pointer type ‘int’ from NULL
mart...@duezer:~/playpen$ 
mart...@duezer:~/playpen$ g++-4.3 -c -pedantic null-conversion.cpp 
mart...@duezer:~/playpen$ g++-4.3 -Wconversion -c -pedantic null-conversion.cpp 
null-conversion.cpp: In function ‘void test()’:
null-conversion.cpp:3: warning: converting to non-pointer type ‘int’ from NULL
mart...@duezer:~/playpen$ 


-- 


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

Reply via email to