From: Paolo Carlini Date: Fri, 21 Oct 2011 18:18:55 +0000 (+0000) Subject: re PR c++/31423 (Improve upon "invalid use of member (did you forget the '&' ?)") X-Git-Tag: releases/gcc-4.7.0~2911 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe66170d5b3b327c3d9cf27def4a8c05aafc2e45;p=thirdparty%2Fgcc.git re PR c++/31423 (Improve upon "invalid use of member (did you forget the '&' ?)") /cp 2011-10-21 Paolo Carlini PR c++/31423 * typeck2.c (cxx_incomplete_type_diagnostic): Improve error message for invalid use of member function. /testsuite 2011-10-21 Paolo Carlini PR c++/31423 * g++.dg/parse/error43.C: New. * g++.dg/parse/error44.C: Likewise. From-SVN: r180309 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 11994ee4b13e..b58ee153457a 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2011-10-21 Paolo Carlini + + PR c++/31423 + * typeck2.c (cxx_incomplete_type_diagnostic): Improve error message + for invalid use of member function. + 2011-10-21 Ville Voutilainen PR c++/50811 diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 580f6690b29d..0cb1104dc384 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -428,8 +428,15 @@ cxx_incomplete_type_diagnostic (const_tree value, const_tree type, 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: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ef3404611df7..ae3e60fddf87 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2011-10-21 Paolo Carlini + + PR c++/31423 + * g++.dg/parse/error43.C: New. + * g++.dg/parse/error44.C: Likewise. + 2011-10-21 H.J. Lu Kirill Yukhin diff --git a/gcc/testsuite/g++.dg/parse/error43.C b/gcc/testsuite/g++.dg/parse/error43.C new file mode 100644 index 000000000000..e352fa5c70d8 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/error43.C @@ -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" } diff --git a/gcc/testsuite/g++.dg/parse/error44.C b/gcc/testsuite/g++.dg/parse/error44.C new file mode 100644 index 000000000000..2ebbe710c7c4 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/error44.C @@ -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 '&'" } +}