Hi,

in these two twin PRs filed by Ian and Gerald, it is pointed out that cases like:

   struct C {
     int f() { return 1; }
   };

   int f(C&c) {
     return ( 1 == c.f );
   }

where the user actually forgot the open-closed round braces are much more likely than cases where an ampersand is missing, still we output

invalid use of member (did you forget the ‘&’ ?)

Thus, the idea of saying instead

invalid use of member (did you forget the ‘()’ ?)

which I implemented in the patchlet below. Alternately we could give both hints, or refer to the argument list.

Tested x86_64-linux.

Thanks,
Paolo.

///////////////////
/cp
2011-10-19  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/31423
        PR c++/48630
        * typeck2.c (cxx_incomplete_type_diagnostic): Improve error message
        for invalid use of member.

/testsuite
2011-10-19  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/31423
        PR c++/48630
        * g++.dg/parse/error42.C: New.



Index: testsuite/g++.dg/parse/error42.C
===================================================================
--- testsuite/g++.dg/parse/error42.C    (revision 0)
+++ testsuite/g++.dg/parse/error42.C    (revision 0)
@@ -0,0 +1,5 @@
+// PR c++/48630
+// { dg-options "" }
+
+class C { public: C* f(); int get(); }; // { dg-error "forget the 
'\\(\\)'|base operand" }
+int f(C* p) { return p->f->get(); }
Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c        (revision 180206)
+++ cp/typeck2.c        (working copy)
@@ -429,7 +429,7 @@ cxx_incomplete_type_diagnostic (const_tree value,
     case OFFSET_TYPE:
     bad_member:
       emit_diagnostic (diag_kind, input_location, 0,
-                      "invalid use of member (did you forget the %<&%> ?)");
+                      "invalid use of member (did you forget the %<()%> ?)");
       break;
 
     case TEMPLATE_TYPE_PARM:

Reply via email to