Hi,

in mainline this ICE on invalid doesn't exist anymore but we may want to avoid issuing the additional redundant "error: cannot convert ‘A::foo’ from type ‘void (A::)()’ to type ‘void (A::*)()’" and/or make the error message more informative by printing the member used invalidly. Tested x86_64-linux.

Thanks, Paolo.

///////////////////////

/cp
2015-10-26  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/67846
        * parser.c (cp_parser_lambda_body): Check lambda_return_type
        return value.
        * typeck2.c (cxx_incomplete_type_diagnostic): Print member or
        member function used invalidly.

/testsuite
2015-10-26  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/67846
        * g++.dg/cpp0x/lambda/lambda-ice15.C: New.
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 229351)
+++ cp/parser.c (working copy)
@@ -9892,7 +9892,12 @@ cp_parser_lambda_body (cp_parser* parser, tree lam
        if (cp_parser_parse_definitely (parser))
          {
            if (!processing_template_decl)
-             apply_deduced_return_type (fco, lambda_return_type (expr));
+             {
+               tree type = lambda_return_type (expr);
+               apply_deduced_return_type (fco, type);
+               if (type == error_mark_node)
+                 expr = error_mark_node;
+             }
 
            /* Will get error here if type not deduced yet.  */
            finish_return_stmt (expr);
Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c        (revision 229351)
+++ cp/typeck2.c        (working copy)
@@ -517,12 +517,12 @@ cxx_incomplete_type_diagnostic (const_tree value,
        if (DECL_FUNCTION_MEMBER_P (member)
            && ! flag_ms_extensions)
          emit_diagnostic (diag_kind, input_location, 0,
-                          "invalid use of member function "
-                          "(did you forget the %<()%> ?)");
+                          "invalid use of member function %qD "
+                          "(did you forget the %<()%> ?)", member);
        else
          emit_diagnostic (diag_kind, input_location, 0,
-                          "invalid use of member "
-                          "(did you forget the %<&%> ?)");
+                          "invalid use of member %qD "
+                          "(did you forget the %<&%> ?)", member);
       }
       break;
 
Index: testsuite/g++.dg/cpp0x/lambda/lambda-ice15.C
===================================================================
--- testsuite/g++.dg/cpp0x/lambda/lambda-ice15.C        (revision 0)
+++ testsuite/g++.dg/cpp0x/lambda/lambda-ice15.C        (working copy)
@@ -0,0 +1,10 @@
+// PR c++/67846
+// { dg-do compile { target c++11 } }
+
+class A
+{
+  void foo ()
+  {
+    [=] { return foo; };  // { dg-error "invalid use of member function" }
+  }
+};

Reply via email to