https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80598

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jason at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Started with r245643.

I wonder if we couldn't do something like following, still set TREE_USED on
where we've previously called mark_used but not really do the rest.
--- gcc/cp/semantics.c.jj       2018-03-06 21:40:35.717360176 +0100
+++ gcc/cp/semantics.c  2018-03-07 18:31:35.782132830 +0100
@@ -3740,10 +3740,15 @@ finish_id_expression (tree id_expression
             But only mark it if it's a complete postfix-expression; in a call,
             ADL might select a different function, and we'll call mark_used in
             build_over_call.  */
-         if (done
-             && !really_overloaded_fn (decl)
-             && !mark_used (first_fn))
-           return error_mark_node;
+          if (!really_overloaded_fn (decl))
+           {
+             if (done && !mark_used (first_fn))
+               return error_mark_node;
+             /* Otherwise in templates mark first_fn as potentially used
+                for the benefit of -Wunused, see PR80598.  */
+             else if (!done && processing_template_decl)
+               TREE_USED (first_fn) = 1;
+           }

          if (!template_arg_p
              && TREE_CODE (first_fn) == FUNCTION_DECL
--- gcc/testsuite/g++.dg/warn/Wunused-function4.C.jj    2018-03-07
18:34:30.463176743 +0100
+++ gcc/testsuite/g++.dg/warn/Wunused-function4.C       2018-03-07
18:33:20.484159148 +0100
@@ -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;
+}

Reply via email to