public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-8604] c++: function NTTP argument considered unused [PR53164, PR105848] Date: Thu, 21 Jul 2022 16:48:12 +0000 (GMT) [thread overview] Message-ID: <20220721164812.A1188384D17E@sourceware.org> (raw) https://gcc.gnu.org/g:670ef5b108d0acfbde96f44b064079f2fa0c92d4 commit r12-8604-g670ef5b108d0acfbde96f44b064079f2fa0c92d4 Author: Patrick Palka <ppalka@redhat.com> Date: Mon Jun 6 14:29:12 2022 -0400 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. (cherry picked from commit 733a792a2b2e1662e738fa358b45a2720a8618a7) Diff: --- gcc/cp/pt.cc | 20 ++++++++++++++++---- gcc/testsuite/g++.dg/template/fn-ptr3.C | 28 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index b2b1a5d1ec6..38c138bd835 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -20926,10 +20926,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; diff --git a/gcc/testsuite/g++.dg/template/fn-ptr3.C b/gcc/testsuite/g++.dg/template/fn-ptr3.C new file mode 100644 index 00000000000..4c651f124f6 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/fn-ptr3.C @@ -0,0 +1,28 @@ +// PR c++/53164 +// PR c++/105848 +// { dg-do link } + +template<class T> +void f(T) { } + +template<void (*P)(int)> +struct A { + static void wrap() { + P(0); + } +}; + +template<void (*P)(char)> +void wrap() { + P(0); +} + +template<int> +void g() { + A<f>::wrap(); + wrap<f>(); +} + +int main() { + g<0>(); +}
reply other threads:[~2022-07-21 16:48 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220721164812.A1188384D17E@sourceware.org \ --to=ppalka@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).