Make conversion warnings work on NULL with -ftrack-macro-expansion
authorDodji Seketeli <dodji@redhat.com>
Mon, 30 Apr 2012 11:42:38 +0000 (11:42 +0000)
committerDodji Seketeli <dodji@gcc.gnu.org>
Mon, 30 Apr 2012 11:42:38 +0000 (13:42 +0200)
commit70dc395a5098e9ae3958e1a317e202358095ed97
treec28481505ac75c540fcd6de15af56c57a92ccb41
parent2d48bdcadfe34cc00ffc7b26687700017b5410c9
Make conversion warnings work on NULL with -ftrack-macro-expansion

There are various conversion related warnings that trigger on
potentially dangerous uses of NULL (or __null).  NULL is defined as a
macro in a system header, so calling warning or warning_at on a
virtual location of NULL yields no diagnostic.  So the test
accompanying this patch (as well as others), was failling when run
with -ftrack-macro-expansion.

I think it's necessary to use the location of NULL that is in the main
source code (instead of, e.g, the spelling location that is in the
system header where the macro is defined) in those cases.  Note that
for __null, we don't have the issue.

I have augmented the test of this patch to check that we don't regress
when handling __null.

Tested on x86_64-unknown-linux-gnu against trunk.

Note that the bootstrap with -ftrack-macro-expansion exhibits other
separate issues that are addressed in subsequent patches.  This patch
just fixes one class of problems.

The patch does pass bootstrap with -ftrack-macro-expansion turned off,
though.

gcc/
* input.h (expansion_point_location_if_in_system_header): Declare
new function.
* input.c (expansion_point_location_if_in_system_header): Define it.
gcc/cp/

* call.c (conversion_null_warnings): Use the new
expansion_point_location_if_in_system_header.
* cvt.c (build_expr_type_conversion): Likewise.
* typeck.c (cp_build_binary_op): Likewise.

gcc/testsuite/

* g++.dg/warn/Wconversion-null-2.C: Add testing for __null,
alongside the previous testing for NULL.

From-SVN: r186972
gcc/ChangeLog
gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/cvt.c
gcc/cp/typeck.c
gcc/input.c
gcc/input.h
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wconversion-null-2.C