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
This commit is contained in:
Paolo Carlini 2011-10-17 17:51:00 +00:00 committed by Paolo Carlini
parent 3e8f763093
commit a7248d5fe3
5 changed files with 45 additions and 5 deletions

View File

@ -1,3 +1,10 @@
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>

View File

@ -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;
}

View File

@ -1,3 +1,9 @@
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

View File

@ -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;
}

View File

@ -0,0 +1,11 @@
// 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" }
}