Commit a7248d5f by Paolo Carlini Committed by Paolo Carlini

re PR c++/44524 (improve diagnostic for . vs -> typo)

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

	PR c++/44524
	* typeck.c (build_class_member_access_expr): Provide a better error
	message for X.Y where X is a pointer to class type.
	(finish_class_member_access_expr): Likewise.

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

	PR c++/44524
	* g++.dg/parse/error41.C: New.
	* g++.dg/parse/error20.C: Adjust.

From-SVN: r180103
parent 3e8f7630
2011-10-17 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/44524
* typeck.c (build_class_member_access_expr): Provide a better error
message for X.Y where X is a pointer to class type.
(finish_class_member_access_expr): Likewise.
2011-10-15 Tom Tromey <tromey@redhat.com>
Dodji Seketeli <dodji@redhat.com>
......
......@@ -2128,8 +2128,16 @@ build_class_member_access_expr (tree object, tree member,
if (!CLASS_TYPE_P (object_type))
{
if (complain & tf_error)
error ("request for member %qD in %qE, which is of non-class type %qT",
member, object, object_type);
{
if (POINTER_TYPE_P (object_type)
&& CLASS_TYPE_P (TREE_TYPE (object_type)))
error ("request for member %qD in %qE, which is of pointer "
"type %qT (maybe you meant to use %<->%> ?)",
member, object, object_type);
else
error ("request for member %qD in %qE, which is of non-class "
"type %qT", member, object, object_type);
}
return error_mark_node;
}
......@@ -2508,8 +2516,16 @@ finish_class_member_access_expr (tree object, tree name, bool template_p,
if (!CLASS_TYPE_P (object_type))
{
if (complain & tf_error)
error ("request for member %qD in %qE, which is of non-class type %qT",
name, object, object_type);
{
if (POINTER_TYPE_P (object_type)
&& CLASS_TYPE_P (TREE_TYPE (object_type)))
error ("request for member %qD in %qE, which is of pointer "
"type %qT (maybe you meant to use %<->%> ?)",
name, object, object_type);
else
error ("request for member %qD in %qE, which is of non-class "
"type %qT", name, object, object_type);
}
return error_mark_node;
}
......
2011-10-17 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/44524
* g++.dg/parse/error41.C: New.
* g++.dg/parse/error20.C: Adjust.
2011-10-17 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50757
* g++.dg/warn/format7.C: New.
* obj-c++.dg/warn7.mm: Likewise.
......
......@@ -12,7 +12,7 @@ struct C {
};
int main() {
C c;
A(c.p.i); // { dg-error "9:request for member 'i' in 'c.C::p', which is of non-class type 'B" }
A(c.p.i); // { dg-error "9:request for member 'i' in 'c.C::p', which is of pointer type 'B" }
return 0;
}
// PR c++/44524
template<typename, typename>
struct map
{
bool empty();
};
int bar(map<int, float> *X) {
return X.empty(); // { dg-error "which is of pointer type 'map" }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment