Patchwork [C++] PR 48489

login
register
mail settings
Submitter Paolo Carlini
Date Oct. 16, 2011, 7:12 p.m.
Message ID <4E9B2C9D.5060803@oracle.com>
Download mbox | patch
Permalink /patch/120056/
State New
Headers show

Comments

Paolo Carlini - Oct. 16, 2011, 7:12 p.m.
Hi,

in this diagnostic PR the issue it that for:

struct Base{ };

struct Concrete : Base
{
void setValue();
};

int main()
{
Concrete d;
d.Base::setValue();
}

the error message is:

48489.C:11:11: error: ‘struct Derived’ has no member named ‘setValue’

instead of:

48489.C:11:11: error: ‘struct Base’ has no member named ‘setValue’

which indeed may be quite confusing.

I'm tweaking the code like the below, thus using the actual access_path 
passed right before to lookup_member. The patch passes the testsuite on 
x86_64-linux. Seems good enough to fix the issue?

Thanks,
Paolo.

//////////////
/cp
2011-10-16  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/48489
	* typeck.c (finish_class_member_access_expr): Fix error call
	for TREE_CODE (access_path) == TREE_BINFO.

/testsuite
2011-10-16  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/48489
	* g++.dg/inherit/error5.C: New.
Paolo Carlini - Oct. 16, 2011, 9 p.m.
On 10/16/2011 09:12 PM, Paolo Carlini wrote:
> 48489.C:11:11: error: ‘struct Derived’ has no member named ‘setValue’
of course there is a typo here, should read

48489.C:11:11: error: ‘struct Concrete’ has no member named ‘setValue’

Paolo.
Jason Merrill - Oct. 17, 2011, 5:06 a.m.
OK.

Jason

Patch

Index: testsuite/g++.dg/inherit/error5.C
===================================================================
--- testsuite/g++.dg/inherit/error5.C	(revision 0)
+++ testsuite/g++.dg/inherit/error5.C	(revision 0)
@@ -0,0 +1,14 @@ 
+// PR c++/48489
+
+struct Base{ };
+
+struct Concrete : Base 
+{
+  void setValue();
+};
+
+int main()
+{
+  Concrete d;
+  d.Base::setValue(); // { dg-error "struct Base" }
+}
Index: cp/typeck.c
===================================================================
--- cp/typeck.c	(revision 180060)
+++ cp/typeck.c	(working copy)
@@ -2591,7 +2591,9 @@  finish_class_member_access_expr (tree object, tree
 	  if (member == NULL_TREE)
 	    {
 	      if (complain & tf_error)
-		error ("%qD has no member named %qE", object_type, name);
+		error ("%qD has no member named %qE",
+		       TREE_CODE (access_path) == TREE_BINFO
+		       ? TREE_TYPE (access_path) : object_type, name);
 	      return error_mark_node;
 	    }
 	  if (member == error_mark_node)