Hi again,
Another acceptable fix is to
-- leave the current diagnostic as is if -fms-extensions
-- suggest '()' is member function
-- otherwise suggest '&'.
Thanks for your help Gaby, in particular about the MS extension which
I had overlooked completely (as any hard-code Linux guy would ;).
Anyway, seriously, I'll try to come up with an improved proposal over
the next days.
Thus I tested on x86_64-linux the below. Ok for mainline?
Thanks,
Paolo.
/////////////////////////
/cp
2011-10-21 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/31423
* typeck2.c (cxx_incomplete_type_diagnostic): Improve error message
for invalid use of member function.
/testsuite
2011-10-21 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/31423
* g++.dg/parse/error43.C: New.
* g++.dg/parse/error44.C: Likewise.
Index: testsuite/g++.dg/parse/error43.C
===================================================================
--- testsuite/g++.dg/parse/error43.C (revision 0)
+++ testsuite/g++.dg/parse/error43.C (revision 0)
@@ -0,0 +1,5 @@
+// PR c++/31423
+// { dg-options "" }
+
+class C { public: C* f(); int get(); };
+int f(C* p) { return p->f->get(); } // { dg-error "forget the '\\(\\)'|base
operand" }
Index: testsuite/g++.dg/parse/error44.C
===================================================================
--- testsuite/g++.dg/parse/error44.C (revision 0)
+++ testsuite/g++.dg/parse/error44.C (revision 0)
@@ -0,0 +1,11 @@
+// PR c++/31423
+// { dg-options "-fms-extensions" }
+
+struct C {
+ int f() { return 1; }
+ int g() { return 2; }
+};
+
+int f(C& c) {
+ return c.g == &c.f; // { dg-error "forget the '&'" }
+}
Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c (revision 180307)
+++ cp/typeck2.c (working copy)
@@ -428,8 +428,15 @@ 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 %<&%> ?)");
+ if (DECL_FUNCTION_MEMBER_P (TREE_OPERAND (value, 1))
+ && ! flag_ms_extensions)
+ emit_diagnostic (diag_kind, input_location, 0,
+ "invalid use of member function "
+ "(did you forget the %<()%> ?)");
+ else
+ emit_diagnostic (diag_kind, input_location, 0,
+ "invalid use of member "
+ "(did you forget the %<&%> ?)");
break;
case TEMPLATE_TYPE_PARM: