Message ID | 4E9F4265.6080809@oracle.com |
---|---|
State | New |
Headers | show |
On Wed, Oct 19, 2011 at 4:34 PM, Paolo Carlini <paolo.carlini@oracle.com> wrote: > 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. I agree that '()' is a better default. But we can do better. We can use the type context, e.g. in initialization or return-statement etc., to decide whether () is intended (by looking at the TREE_TYPE of a member function type), and only in cases where we can't tell we suggest both alternative: (did you intend a function call or address of non-static member function?)
Surely we should only make this change for function members. Jason
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: