From ffd99ef2488db55f3c772742371f17282f115265 Mon Sep 17 00:00:00 2001 From: jakub Date: Thu, 8 Mar 2018 21:18:50 +0000 Subject: [PATCH] PR c++/80598 * call.c (build_over_call): In templates set TREE_USED (first_fn) when not calling mark_used for the benefit of -Wunused-function warning. * g++.dg/warn/Wunused-function4.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@258370 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/call.c | 4 ++++ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/warn/Wunused-function4.C | 21 +++++++++++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-function4.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9dd7c179710..3c1e4c76a06 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2018-03-08 Jason Merrill + Jakub Jelinek + + PR c++/80598 + * call.c (build_over_call): In templates set TREE_USED (first_fn) when + not calling mark_used for the benefit of -Wunused-function warning. + 2018-03-06 Jason Merrill * lambda.c (is_capture_proxy_with_ref): Remove. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index f83d51f3457..fd6528fcaeb 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -7634,6 +7634,10 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) if (undeduced_auto_decl (fn)) mark_used (fn, complain); + else + /* Otherwise set TREE_USED for the benefit of -Wunused-function. + See PR80598. */ + TREE_USED (fn) = 1; return_type = TREE_TYPE (TREE_TYPE (fn)); nargs = vec_safe_length (args); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 32740bf3710..1917aef3cf1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2018-03-08 Jakub Jelinek + PR c++/80598 + * g++.dg/warn/Wunused-function4.C: New test. + PR inline-asm/84742 * gcc.target/i386/pr84742-1.c: New test. * gcc.target/i386/pr84742-2.c: New test. diff --git a/gcc/testsuite/g++.dg/warn/Wunused-function4.C b/gcc/testsuite/g++.dg/warn/Wunused-function4.C new file mode 100644 index 00000000000..00d5d70fc90 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-function4.C @@ -0,0 +1,21 @@ +// PR c++/80598 +// { dg-do compile } +// { dg-options "-Wunused-function" } + +static void +foo () // { dg-bogus "defined but not used" } +{ +} + +static void +bar () // { dg-warning "defined but not used" } +{ +} + +template +int +baz (T x) +{ + foo (); + return 0; +} -- 2.11.4.GIT