Make conversion warnings work on NULL with -ftrack-macro-expansion
authordodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 30 Apr 2012 11:42:38 +0000 (11:42 +0000)
committerdodji <dodji@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 30 Apr 2012 11:42:38 +0000 (11:42 +0000)
commitdb30b35189c3090d0739f86df53e954125cf90b9
treec28481505ac75c540fcd6de15af56c57a92ccb41
parent18f0e0e551a995687e1822aabb9b7d7ee8f11492
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@186972 138bc75d-0d04-0410-961f-82ee72b054a4
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