Bug 48420 - Missed -Wconversion-null warning when passing const bool to T*
Summary: Missed -Wconversion-null warning when passing const bool to T*
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.7.0
Assignee: Paolo Carlini
URL:
Keywords:
: 51531 53207 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-04-02 21:38 UTC by Jeffrey Yasskin
Modified: 2012-05-03 01:35 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-09-28 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeffrey Yasskin 2011-04-02 21:38:41 UTC
$ g++-mp-4.6 -Wconversion-null -c test.cc
dhcp-172-19-248-71:~/tmp$ cat test.cc
void foo(int* p);

void bar() {
    const bool kDebugMode = false;  // NULL pointer constant.
    foo(kDebugMode);  // But no warning!
}
$ g++-mp-4.6 -Wconversion-null -c test.cc
$ 

Changing the kDebugMode to 'false' or a false expression involving an enum triggers the warning.
Comment 1 Paolo Carlini 2011-09-28 20:03:34 UTC
Interestingly, in C++0x mode it works, obviously thanks to the work on constexpr. Do you really want it for C++98 too? ;)
Comment 2 Paolo Carlini 2011-09-28 20:05:32 UTC
Oops, sorry, got confused, in C++0x it's an hard error. Uhmmm.
Comment 3 Paolo Carlini 2011-11-03 01:19:36 UTC
On it.
Comment 4 paolo@gcc.gnu.org 2011-11-04 16:31:23 UTC
Author: paolo
Date: Fri Nov  4 16:31:18 2011
New Revision: 180963

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=180963
Log:
/cp
2011-11-04  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/48420
	* call.c (conversion_null_warnings): For 'false' to NULL pointer,
	just check that TREE_TYPE (expr) is a BOOLEAN_TYPE.

/testsuite
2011-11-04  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/48420
	* g++.dg/warn/Wconversion-null-3.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/warn/Wconversion-null-3.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Paolo Carlini 2011-11-04 16:32:51 UTC
Fixed for 4.7.0.
Comment 6 Jonathan Wakely 2011-12-13 19:59:38 UTC
*** Bug 51531 has been marked as a duplicate of this bug. ***
Comment 7 Paolo Carlini 2012-05-03 01:35:04 UTC
*** Bug 53207 has been marked as a duplicate of this bug. ***