public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] PR 44524
@ 2011-10-17 13:49 Paolo Carlini
  2011-10-17 14:02 ` Gabriel Dos Reis
  2011-10-17 18:31 ` Jason Merrill
  0 siblings, 2 replies; 4+ messages in thread
From: Paolo Carlini @ 2011-10-17 13:49 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 203 bytes --]

Hi,

here submitter requests a more accurate error message for X.Y where X is 
a pointer to class type. Thus the below, tested x86_64-linux.

Ok for mainline?

Thanks,
Paolo.

//////////////////////////

[-- Attachment #2: CL_44524 --]
[-- Type: text/plain, Size: 389 bytes --]

/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.

[-- Attachment #3: patch_44524 --]
[-- Type: text/plain, Size: 2395 bytes --]

Index: testsuite/g++.dg/parse/error20.C
===================================================================
--- testsuite/g++.dg/parse/error20.C	(revision 180087)
+++ testsuite/g++.dg/parse/error20.C	(working copy)
@@ -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 has pointer type 'B" }
   return 0;
 }
 
Index: testsuite/g++.dg/parse/error41.C
===================================================================
--- testsuite/g++.dg/parse/error41.C	(revision 0)
+++ testsuite/g++.dg/parse/error41.C	(revision 0)
@@ -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 has pointer type 'map" }
+}
Index: cp/typeck.c
===================================================================
--- cp/typeck.c	(revision 180087)
+++ cp/typeck.c	(working copy)
@@ -2128,8 +2128,16 @@ build_class_member_access_expr (tree object, tree
   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 has 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
   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 has 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;
     }
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [C++ Patch] PR 44524
  2011-10-17 13:49 [C++ Patch] PR 44524 Paolo Carlini
@ 2011-10-17 14:02 ` Gabriel Dos Reis
  2011-10-17 14:27   ` Paolo Carlini
  2011-10-17 18:31 ` Jason Merrill
  1 sibling, 1 reply; 4+ messages in thread
From: Gabriel Dos Reis @ 2011-10-17 14:02 UTC (permalink / raw)
  To: Paolo Carlini; +Cc: gcc-patches, Jason Merrill

On Mon, Oct 17, 2011 at 8:32 AM, Paolo Carlini <paolo.carlini@oracle.com> wrote:
> Hi,
>
> here submitter requests a more accurate error message for X.Y where X is a
> pointer to class type. Thus the below, tested x86_64-linux.
>
> Ok for mainline?

s/is of pointer type/has pointer type/g


>
> Thanks,
> Paolo.
>
> //////////////////////////
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [C++ Patch] PR 44524
  2011-10-17 14:02 ` Gabriel Dos Reis
@ 2011-10-17 14:27   ` Paolo Carlini
  0 siblings, 0 replies; 4+ messages in thread
From: Paolo Carlini @ 2011-10-17 14:27 UTC (permalink / raw)
  To: Gabriel Dos Reis; +Cc: gcc-patches, Jason Merrill

On 10/17/2011 03:39 PM, Gabriel Dos Reis wrote:
> On Mon, Oct 17, 2011 at 8:32 AM, Paolo Carlini<paolo.carlini@oracle.com>  wrote:
>> Hi,
>>
>> here submitter requests a more accurate error message for X.Y where X is a
>> pointer to class type. Thus the below, tested x86_64-linux.
>>
>> Ok for mainline?
> s/is of pointer type/has pointer type/g
Thanks, changed in my local tree. By the way, I wondered that, then 
found a couple of instances of 'has pointer' in the tree, but only in 
comments, if I remember correctly.

Paolo.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [C++ Patch] PR 44524
  2011-10-17 13:49 [C++ Patch] PR 44524 Paolo Carlini
  2011-10-17 14:02 ` Gabriel Dos Reis
@ 2011-10-17 18:31 ` Jason Merrill
  1 sibling, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2011-10-17 18:31 UTC (permalink / raw)
  To: Paolo Carlini; +Cc: gcc-patches

OK.

Jason

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-10-17 17:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-17 13:49 [C++ Patch] PR 44524 Paolo Carlini
2011-10-17 14:02 ` Gabriel Dos Reis
2011-10-17 14:27   ` Paolo Carlini
2011-10-17 18:31 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).