]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/31423 (Improve upon "invalid use of member (did you forget the '&' ?)")
authorPaolo Carlini <paolo.carlini@oracle.com>
Fri, 21 Oct 2011 18:18:55 +0000 (18:18 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Fri, 21 Oct 2011 18:18:55 +0000 (18:18 +0000)
/cp
2011-10-21  Paolo Carlini  <paolo.carlini@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.carlini@oracle.com>

PR c++/31423
* g++.dg/parse/error43.C: New.
* g++.dg/parse/error44.C: Likewise.

From-SVN: r180309

gcc/cp/ChangeLog
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/error43.C [new file with mode: 0644]
gcc/testsuite/g++.dg/parse/error44.C [new file with mode: 0644]

index 11994ee4b13e8f9624861275e3e95d7692190122..b58ee153457a9cf94e8f96c1f5ad2df65ed7725b 100644 (file)
@@ -1,3 +1,9 @@
+2011-10-21  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/31423
+       * typeck2.c (cxx_incomplete_type_diagnostic): Improve error message
+       for invalid use of member function.
+
 2011-10-21  Ville Voutilainen  <ville.voutilainen@gmail.com>
 
        PR c++/50811
index 580f6690b29d935f19517097039fb09b0b1cca35..0cb1104dc384336b8486b58c65b851d2e8f9473a 100644 (file)
@@ -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:
index ef3404611df70772ca2d8defb2174d56a950cd96..ae3e60fddf87a9ff1f3521327766f0931991239d 100644 (file)
@@ -1,3 +1,9 @@
+2011-10-21  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/31423
+       * g++.dg/parse/error43.C: New.
+       * g++.dg/parse/error44.C: Likewise.
+
 2011-10-21  H.J. Lu  <hongjiu.lu@intel.com>
            Kirill Yukhin  <kirill.yukhin@intel.com>
 
diff --git a/gcc/testsuite/g++.dg/parse/error43.C b/gcc/testsuite/g++.dg/parse/error43.C
new file mode 100644 (file)
index 0000000..e352fa5
--- /dev/null
@@ -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 (file)
index 0000000..2ebbe71
--- /dev/null
@@ -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 '&'" }
+}