diff mbox

[C++] PR 33101

Message ID 539B4998.6040004@oracle.com
State New
Headers show

Commit Message

Paolo Carlini June 13, 2014, 6:57 p.m. UTC
Hi,

On 06/13/2014 08:11 PM, Jason Merrill wrote:
> On 06/13/2014 01:45 PM, Paolo Carlini wrote:
>> But it doesn't work here, doesn't do anything fancy, it exactly prints
>> 'v' and nothing else.
>
> That seems to be a bug in type_to_string, which sees that "void" 
> starts with "v" and concludes that they are the same.  Oops.
This pair old bug, new testcase is really diabolic ;) Fixing 
type_to_string seems easy. I'm finishing testing the below.

Comments

Jason Merrill June 14, 2014, 10:17 p.m. UTC | #1
OK, thanks.  :)

Jason
Paolo Carlini June 14, 2014, 11:01 p.m. UTC | #2
Hi,

On 06/15/2014 12:17 AM, Jason Merrill wrote:
> OK, thanks.  :)
Committed... but, I don't think we are done yet, because it seems to me 
that DR577 means that in C++11 mode we have to accept the typedef?!? 
That's what current icc does... (I thought the issue was only about 
clearer diagnostic ;)

Paolo.
Jason Merrill June 15, 2014, 1:37 p.m. UTC | #3
On 06/15/2014 01:01 AM, Paolo Carlini wrote:
> Committed... but, I don't think we are done yet, because it seems to me
> that DR577 means that in C++11 mode we have to accept the typedef?!?

Hmm, apparently so.  Might as well apply the DR to C++98 mode as well.

Jason
Paolo Carlini June 16, 2014, 7:14 a.m. UTC | #4
On 15/06/14 15:37, Jason Merrill wrote:
> On 06/15/2014 01:01 AM, Paolo Carlini wrote:
>> Committed... but, I don't think we are done yet, because it seems to me
>> that DR577 means that in C++11 mode we have to accept the typedef?!?
> Hmm, apparently so.  Might as well apply the DR to C++98 mode as well.
Agreed, definitely makes things easier (probably will be next week, as 
soon as I'm back from the Meeting)

Thanks,
Paolo.
diff mbox

Patch

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 211609)
+++ cp/decl.c	(working copy)
@@ -11137,12 +11137,24 @@  grokparms (tree parmlist, tree *parms)
       type = TREE_TYPE (decl);
       if (VOID_TYPE_P (type))
 	{
-	  if (same_type_p (type, void_type_node)
-	      && DECL_SELF_REFERENCE_P (type)
-	      && !DECL_NAME (decl) && !result && TREE_CHAIN (parm) == void_list_node)
+	  if (type == void_type_node
+	      && !init
+	      && !DECL_NAME (decl) && !result
+	      && TREE_CHAIN (parm) == void_list_node)
 	    /* this is a parmlist of `(void)', which is ok.  */
 	    break;
-	  cxx_incomplete_type_error (decl, type);
+	  else if (typedef_variant_p (type))
+	    error_at (DECL_SOURCE_LOCATION (decl),
+		      "invalid use of typedef-name %qT in "
+		      "parameter declaration", type);
+	  else if (cv_qualified_p (type))
+	    error_at (DECL_SOURCE_LOCATION (decl),
+		      "invalid use of cv-qualified type %qT in "
+		      "parameter declaration", type);
+	  else
+	    error_at (DECL_SOURCE_LOCATION (decl),
+		      "invalid use of type %<void%> in parameter "
+		      "declaration");
 	  /* It's not a good idea to actually create parameters of
 	     type `void'; other parts of the compiler assume that a
 	     void type terminates the parameter list.  */
Index: cp/error.c
===================================================================
--- cp/error.c	(revision 211609)
+++ cp/error.c	(working copy)
@@ -2922,7 +2922,7 @@  type_to_string (tree typ, int verbose)
   if (typ && TYPE_P (typ) && typ != TYPE_CANONICAL (typ)
       && !uses_template_parms (typ))
     {
-      int aka_start; char *p;
+      int aka_start, aka_len; char *p;
       struct obstack *ob = pp_buffer (cxx_pp)->obstack;
       /* Remember the end of the initial dump.  */
       int len = obstack_object_size (ob);
@@ -2932,10 +2932,11 @@  type_to_string (tree typ, int verbose)
       /* And remember the start of the aka dump.  */
       aka_start = obstack_object_size (ob);
       dump_type (cxx_pp, aka, flags);
+      aka_len = obstack_object_size (ob) - aka_start;
       pp_right_brace (cxx_pp);
       p = (char*)obstack_base (ob);
       /* If they are identical, cut off the aka with a NUL.  */
-      if (memcmp (p, p+aka_start, len) == 0)
+      if (len == aka_len && memcmp (p, p+aka_start, len) == 0)
 	p[len] = '\0';
     }
   return pp_ggc_formatted_text (cxx_pp);
Index: testsuite/g++.dg/conversion/err-recover1.C
===================================================================
--- testsuite/g++.dg/conversion/err-recover1.C	(revision 211609)
+++ testsuite/g++.dg/conversion/err-recover1.C	(working copy)
@@ -1,6 +1,6 @@ 
 // PR c++/42219
 
-void foo(const void);		// { dg-error "incomplete|const" }
+void foo(const void);		// { dg-error "invalid use of cv-qualified" }
 
 void bar()
 {
Index: testsuite/g++.dg/other/void3.C
===================================================================
--- testsuite/g++.dg/other/void3.C	(revision 0)
+++ testsuite/g++.dg/other/void3.C	(working copy)
@@ -0,0 +1,4 @@ 
+// PR c++/33101
+
+typedef void v;
+typedef v (*pf)(v);  // { dg-error "invalid use of typedef-name" }