Hi,

I think submitters have a point that it doesn't make much sense to warn about unused parameters of defaulted functions: evidently those exist only for documentation purposes. The actual warning is produced by do_warn_unused_parameter, which belongs to gcc/function.c, thus the simplest solution I have been able to figure out for our front-end issue is setting the TREE_NO_WARNING bit, in defaultable_fn_check. I don't think we risk suppressing any other warnings.

Tested x86_64-linux.

Thanks,
Paolo.

/////////////////////////
/cp
2013-05-22  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/57211
        * method.c (defaultable_fn_check): Avoid do_warn_unused_parameter
        warnings about defaulted functions.

/testsuite
2013-05-22  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/57211
        * g++.dg/cpp0x/Wunused-parm.C: New.
Index: cp/method.c
===================================================================
--- cp/method.c (revision 199164)
+++ cp/method.c (working copy)
@@ -1864,13 +1864,19 @@ defaultable_fn_check (tree fn)
     }
   else
     {
-      tree t = FUNCTION_FIRST_USER_PARMTYPE (fn);
-      for (; t && t != void_list_node; t = TREE_CHAIN (t))
+      for (tree t = FUNCTION_FIRST_USER_PARMTYPE (fn);
+          t && t != void_list_node; t = TREE_CHAIN (t))
        if (TREE_PURPOSE (t))
          {
            error ("defaulted function %q+D with default argument", fn);
            break;
          }
+
+      /* Avoid do_warn_unused_parameter warnings.  */
+      for (tree p = FUNCTION_FIRST_USER_PARM (fn); p; p = DECL_CHAIN (p))
+       if (DECL_NAME (p))
+         TREE_NO_WARNING (p) = 1;
+
       if (TYPE_BEING_DEFINED (DECL_CONTEXT (fn)))
        /* Defer checking.  */;
       else if (!processing_template_decl)
Index: testsuite/g++.dg/cpp0x/Wunused-parm.C
===================================================================
--- testsuite/g++.dg/cpp0x/Wunused-parm.C       (revision 0)
+++ testsuite/g++.dg/cpp0x/Wunused-parm.C       (working copy)
@@ -0,0 +1,23 @@
+// PR c++/57211
+// { dg-options "-std=c++11 -Wunused-parameter" }
+
+template <class T> T&& move(T&);
+
+struct A
+{
+  struct B
+  {
+    B& operator=(B&&);
+  };
+
+  B f;
+
+  A& operator=(A&& p) = default;
+};
+
+int main()
+{
+  A a;
+  A b;
+  b = move(a);
+}

Reply via email to