[PR c++/84943] mark function as used when taking its address
commite8a88621f3a4c3ede112c5f8d7c11c99e303dc95
authoraoliva <aoliva@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 4 Apr 2018 03:40:29 +0000 (4 03:40 +0000)
committeraoliva <aoliva@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 4 Apr 2018 03:40:29 +0000 (4 03:40 +0000)
treef4ccbb78b6d042b7a3a6aaf99f9c3ad3a86e65d8
parent1e2437963b91d60ce09f34778e73cd949f0fb296
[PR c++/84943] mark function as used when taking its address

fn[0]() ICEd because we would fold the INDIRECT_REF used for the
array indexing while building the address for the call, after not
finding the decl hiding there at first.  But the decl would be exposed
by the folding, and then lower layers would complain we had the decl,
after all, but it wasn't one of the artificial or special functions
that could be called without being marked as used.

This patch arranges for a FUNCTION_DECL to be marked as used when
taking its address, just like we already did when taking the address
of a static function to call it as a member function (i.e. using the
obj.fn() notation).  However, we shouldn't mark functions as used when
just performing overload resolution, lest we might instantiate
templates we shouldn't, as in g++.dg/overload/template1.C, so we
adjust mark_used to return early when testing conversions.

for  gcc/cp/ChangeLog

PR c++/84943
* typeck.c (cp_build_addr_expr_1): Mark FUNCTION_DECL as
used.
* decl2.c (mark_used): Return without effects if tf_conv.

for  gcc/testsuite/ChangeLog

PR c++/84943
* g++.dg/pr84943.C: New.
* g++.dg/pr84943-2.C: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@259067 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/pr84943-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/pr84943.C [new file with mode: 0644]