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.carl...@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.carl...@oracle.com>

        PR c++/48489
        * g++.dg/inherit/error5.C: New.
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)

Reply via email to