]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/80598 (-Wunused triggers for functions used in uninstantiated...
authorJakub Jelinek <jakub@redhat.com>
Fri, 22 Jun 2018 20:32:15 +0000 (22:32 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 22 Jun 2018 20:32:15 +0000 (22:32 +0200)
Backported from mainline
2018-03-08  Jason Merrill  <jason@redhat.com>
    Jakub Jelinek  <jakub@redhat.com>

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.

From-SVN: r261915

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wunused-function4.C [new file with mode: 0644]

index 5df7e4235251ab2e9baf3c55c1328d854492ed44..1b2cc21a981e200b0e6aa0fd1526bf6910699ba0 100644 (file)
@@ -1,6 +1,13 @@
 2018-06-22  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2018-03-08  Jason Merrill  <jason@redhat.com>
+                   Jakub Jelinek  <jakub@redhat.com>
+
+       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-02  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/84662
index 012134fd47adf0adbef4e20923177fd9e9c80ef7..16a6a33bca76799dd0f6eb3f74f183a7bdfb1c24 100644 (file)
@@ -7568,6 +7568,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);
index 98a4db6feddd43ed2cf6e9ac07dccceafee9ec02..a00300dfb6ad754bd849f5f62b8af20eb3085ebf 100644 (file)
@@ -1,6 +1,12 @@
 2018-06-22  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2018-03-08  Jason Merrill  <jason@redhat.com>
+                   Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/80598
+       * g++.dg/warn/Wunused-function4.C: New test.
+
        2018-03-08  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/84739
diff --git a/gcc/testsuite/g++.dg/warn/Wunused-function4.C b/gcc/testsuite/g++.dg/warn/Wunused-function4.C
new file mode 100644 (file)
index 0000000..00d5d70
--- /dev/null
@@ -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 <class T>
+int
+baz (T x)
+{
+  foo ();
+  return 0;
+}