diff options
author | Patrick Palka <ppalka@redhat.com> | 2022-06-06 14:29:12 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2022-06-06 14:29:12 -0400 |
commit | 733a792a2b2e1662e738fa358b45a2720a8618a7 (patch) | |
tree | 5ecd402a3fb2d49af069ada42e8500df021612a3 /gcc/cp/pt.cc | |
parent | 36bd6eafb6062f1fb92a994538c6ed017ced670b (diff) | |
download | gcc-733a792a2b2e1662e738fa358b45a2720a8618a7.zip gcc-733a792a2b2e1662e738fa358b45a2720a8618a7.tar.gz gcc-733a792a2b2e1662e738fa358b45a2720a8618a7.tar.bz2 |
c++: function NTTP argument considered unused [PR53164, PR105848]
Here at parse time the template argument f (an OVERLOAD) in A<f> gets
resolved ahead of time to the FUNCTION_DECL f<int>, and we defer marking
f<int> as used until instantiation (of g) as usual.
Later when instantiating g the type A<f> (where f has already been
resolved) is non-dependent, so tsubst_aggr_type avoids re-processing its
template arguments, and we end up never actually marking f<int> as used
(which means we never instantiate it) even though A<f>::h() later calls
it, leading to a link error.
This patch works around this issue by looking through ADDR_EXPR when
calling mark_used on the substituted callee of a CALL_EXPR.
PR c++/53164
PR c++/105848
gcc/cp/ChangeLog:
* pt.cc (tsubst_copy_and_build) <case CALL_EXPR>: Look through an
ADDR_EXPR callee when calling mark_used.
gcc/testsuite/ChangeLog:
* g++.dg/template/fn-ptr3.C: New test.
Diffstat (limited to 'gcc/cp/pt.cc')
-rw-r--r-- | gcc/cp/pt.cc | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 59b9431..dcacba5 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -20884,10 +20884,22 @@ tsubst_copy_and_build (tree t, } /* Remember that there was a reference to this entity. */ - if (function != NULL_TREE - && DECL_P (function) - && !mark_used (function, complain) && !(complain & tf_error)) - RETURN (error_mark_node); + if (function != NULL_TREE) + { + tree inner = function; + if (TREE_CODE (inner) == ADDR_EXPR + && TREE_CODE (TREE_OPERAND (inner, 0)) == FUNCTION_DECL) + /* We should already have called mark_used when taking the + address of this function, but do so again anyway to make + sure it's odr-used: at worst this is a no-op, but if we + obtained this FUNCTION_DECL as part of ahead-of-time overload + resolution then that call to mark_used wouldn't have marked it + odr-used yet (53164). */ + inner = TREE_OPERAND (inner, 0); + if (DECL_P (inner) + && !mark_used (inner, complain) && !(complain & tf_error)) + RETURN (error_mark_node); + } if (!maybe_fold_fn_template_args (function, complain)) return error_mark_node; |