re PR c++/66130 ("invalid use of non-static member function" message could be clearer)
authorManuel López-Ibáñez <manu@gcc.gnu.org>
Wed, 3 Jun 2015 19:23:20 +0000 (19:23 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 3 Jun 2015 19:23:20 +0000 (19:23 +0000)
2015-06-03  Manuel López-Ibáñez  <manu@gcc.gnu.org>
    Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/66130
* typeck.c (invalid_nonstatic_memfn_p): Add location_t parameter and
use it in the diagnostic.
(decay_conversion): Adjust call.
* semantics.c (finish_decltype_type): Likewise.
* call.c (resolve_args, build_new_op_1,
perform_implicit_conversion_flags): Adjust calls.
* cvt.c (ocp_convert, convert_to_void): Likewise.
* cp-tree.h (invalid_nonstatic_memfn_p): Update declaration.

2015-06-03  Manuel López-Ibáñez  <manu@gcc.gnu.org>
    Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/66130
* g++.dg/other/pr66130.C: New.
* g++.dg/cpp0x/pr66130.C: Likewise.

Co-Authored-By: Paolo Carlini <paolo.carlini@oracle.com>
From-SVN: r224099

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/cp-tree.h
gcc/cp/cvt.c
gcc/cp/semantics.c
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/pr66130.C [new file with mode: 0644]
gcc/testsuite/g++.dg/other/pr66130.C [new file with mode: 0644]

index 2c61d5577162801f8227b55eba1ace317a450924..39888b970b0ee1f6c884c8f78a225dc101562286 100644 (file)
@@ -1,3 +1,16 @@
+2015-06-03  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+           Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/66130
+       * typeck.c (invalid_nonstatic_memfn_p): Add location_t parameter and
+       use it in the diagnostic.
+       (decay_conversion): Adjust call.
+       * semantics.c (finish_decltype_type): Likewise.
+       * call.c (resolve_args, build_new_op_1,
+       perform_implicit_conversion_flags): Adjust calls.
+       * cvt.c (ocp_convert, convert_to_void): Likewise.
+       * cp-tree.h (invalid_nonstatic_memfn_p): Update declaration.
+
 2015-06-03  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * decl.c (check_tag_decl): Use declspecs->locations as locations in
index bad49f15d4867e8cf75cb48d58bbb0adc3cc783d..71f7e06013c2fa3f474df8556d801d2f651c3864 100644 (file)
@@ -3941,7 +3941,7 @@ resolve_args (vec<tree, va_gc> *args, tsubst_flags_t complain)
            error ("invalid use of void expression");
          return NULL;
        }
-      else if (invalid_nonstatic_memfn_p (arg, complain))
+      else if (invalid_nonstatic_memfn_p (input_location, arg, complain))
        return NULL;
     }
   return args;
@@ -5542,9 +5542,9 @@ build_new_op_1 (location_t loc, enum tree_code code, int flags, tree arg1,
                /* If one of the arguments of the operator represents
                   an invalid use of member function pointer, try to report
                   a meaningful error ...  */
-               if (invalid_nonstatic_memfn_p (arg1, tf_error)
-                   || invalid_nonstatic_memfn_p (arg2, tf_error)
-                   || invalid_nonstatic_memfn_p (arg3, tf_error))
+             if (invalid_nonstatic_memfn_p (loc, arg1, tf_error)
+                   || invalid_nonstatic_memfn_p (loc, arg2, tf_error)
+                   || invalid_nonstatic_memfn_p (loc, arg3, tf_error))
                  /* We displayed the error message.  */;
                else
                  {
@@ -9445,7 +9445,7 @@ perform_implicit_conversion_flags (tree type, tree expr,
             Call instantiate_type to get good error messages.  */
          if (TREE_TYPE (expr) == unknown_type_node)
            instantiate_type (type, expr, complain);
-         else if (invalid_nonstatic_memfn_p (expr, complain))
+         else if (invalid_nonstatic_memfn_p (loc, expr, complain))
            /* We gave an error.  */;
          else
            error_at (loc, "could not convert %qE from %qT to %qT", expr,
index 9107fa68b642acf0abadbfc2e542e2dd10719219..76be7cca6f12656b3d3b72436006c7839f32729f 100644 (file)
@@ -6281,7 +6281,8 @@ extern tree build_address                 (tree);
 extern tree build_nop                          (tree, tree);
 extern tree non_reference                      (tree);
 extern tree lookup_anon_field                  (tree, tree);
-extern bool invalid_nonstatic_memfn_p          (tree, tsubst_flags_t);
+extern bool invalid_nonstatic_memfn_p          (location_t, tree,
+                                                tsubst_flags_t);
 extern tree convert_member_func_to_ptr         (tree, tree, tsubst_flags_t);
 extern tree convert_ptrmem                     (tree, tree, bool, bool,
                                                 tsubst_flags_t);
index 9aa9006f1928025e9db72127dcc87899c6f11eec..ae0326eaba2aef4db1639173ac79ce585edb4322 100644 (file)
@@ -902,7 +902,7 @@ ocp_convert (tree type, tree expr, int convtype, int flags,
     {
       /* If the conversion failed and expr was an invalid use of pointer to
         member function, try to report a meaningful error.  */
-      if (invalid_nonstatic_memfn_p (expr, complain))
+      if (invalid_nonstatic_memfn_p (loc, expr, complain))
        /* We displayed the error message.  */;
       else
        error_at (loc, "conversion from %qT to non-scalar type %qT requested",
@@ -960,7 +960,7 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
 
   if (!TREE_TYPE (expr))
     return expr;
-  if (invalid_nonstatic_memfn_p (expr, complain))
+  if (invalid_nonstatic_memfn_p (loc, expr, complain))
     return error_mark_node;
   if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
     {
index 565941f0f5e6c9c4879790757362384dd121070c..b1c280f67481ad6e98a9fbf02893098a9d1b25d1 100644 (file)
@@ -7237,7 +7237,7 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
 
   expr = resolve_nondeduced_context (expr);
 
-  if (invalid_nonstatic_memfn_p (expr, complain))
+  if (invalid_nonstatic_memfn_p (input_location, expr, complain))
     return error_mark_node;
 
   if (type_unknown_p (expr))
index fef4f4f1304ab84ef8d134586ae90e153790866f..4da6275f0df007b7f2002dabc5202a0b4d4f598f 100644 (file)
@@ -1810,7 +1810,7 @@ cxx_alignas_expr (tree e)
    violates these rules.  */
 
 bool
-invalid_nonstatic_memfn_p (tree expr, tsubst_flags_t complain)
+invalid_nonstatic_memfn_p (location_t loc, tree expr, tsubst_flags_t complain)
 {
   if (expr == NULL_TREE)
     return false;
@@ -1822,7 +1822,17 @@ invalid_nonstatic_memfn_p (tree expr, tsubst_flags_t complain)
   if (DECL_NONSTATIC_MEMBER_FUNCTION_P (expr))
     {
       if (complain & tf_error)
-        error ("invalid use of non-static member function");
+       {
+         if (DECL_P (expr))
+           {
+             error_at (loc, "invalid use of non-static member function %qD",
+                       expr);
+             inform (DECL_SOURCE_LOCATION (expr), "declared here");
+           }
+         else
+           error_at (loc, "invalid use of non-static member function of "
+                     "type %qT", TREE_TYPE (expr));
+       }
       return true;
     }
   return false;
@@ -1946,7 +1956,7 @@ decay_conversion (tree exp, tsubst_flags_t complain)
        error_at (loc, "void value not ignored as it ought to be");
       return error_mark_node;
     }
-  if (invalid_nonstatic_memfn_p (exp, complain))
+  if (invalid_nonstatic_memfn_p (loc, exp, complain))
     return error_mark_node;
   if (code == FUNCTION_TYPE || is_overloaded_fn (exp))
     return cp_build_addr_expr (exp, complain);
index 53c7018f3e078da2c12be56be77dfde8c5496d41..a74be77df88b4d59d6589fb78a425c0eb56a2bde 100644 (file)
@@ -1,3 +1,10 @@
+2015-06-03  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+           Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/66130
+       * g++.dg/other/pr66130.C: New.
+       * g++.dg/cpp0x/pr66130.C: Likewise.
+
 2015-06-03  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * g++.dg/cpp0x/decl-loc1.C: New.
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr66130.C b/gcc/testsuite/g++.dg/cpp0x/pr66130.C
new file mode 100644 (file)
index 0000000..5d4a72e
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/66130
+// { dg-do compile { target c++11 } }
+
+struct Local
+{
+  void f();
+};
+
+Local *l;
+void (Local::*ptr)();
+decltype((l->*ptr)) i;  // { dg-error "member function of type 'void \\(Local::\\)\\(\\)'" }
diff --git a/gcc/testsuite/g++.dg/other/pr66130.C b/gcc/testsuite/g++.dg/other/pr66130.C
new file mode 100644 (file)
index 0000000..b109b93
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/66130
+
+struct X {
+  X(void *);
+  void m();  // { dg-message "declared here" }
+};
+
+struct Y : public X{
+  Y(void*a, void *b) : X(m), mb(b) { }  // { dg-error "member function 'void X::m\\(\\)'" }
+  void *mb;
+};