]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/33101 ([DR 577] allow typedefs for void in empty parameter list)
authorPaolo Carlini <paolo.carlini@oracle.com>
Sat, 14 Jun 2014 22:55:40 +0000 (22:55 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Sat, 14 Jun 2014 22:55:40 +0000 (22:55 +0000)
/cp
2014-06-14  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/33101
* decl.c (grokparms): Improve error message about void parameters.
* error.c (type_to_string): Fix aka cut off code.

/testsuite
2014-06-14  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/33101
* g++.dg/other/void3.C: New.
* g++.dg/conversion/err-recover1.C: Update.

From-SVN: r211673

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/error.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/conversion/err-recover1.C
gcc/testsuite/g++.dg/other/void3.C [new file with mode: 0644]

index 5fac4a52dab1b4c7621f72d41a4de878afcd7cfd..52744d80919293aa450a99786284d4cbd446206e 100644 (file)
@@ -1,3 +1,9 @@
+2014-06-14  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/33101
+       * decl.c (grokparms): Improve error message about void parameters.
+       * error.c (type_to_string): Fix aka cut off code.
+
 2014-06-12  Jason Merrill  <jason@redhat.com>
 
        * call.c (convert_arg_to_ellipsis): Use abi_version_crosses.
index c472ee5522a475a8a3f2ee1ced7f63e7012263a8..29082240d843836389f22838fe0a0153dcf3681c 100644 (file)
@@ -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 b3b5bbb0971405acd7a6b287b6295f636f0b4f8e..27a167a001a839ec02e1558ea55d604f8ad8746f 100644 (file)
@@ -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 919185df93ffb4beb41dc234f08692fd424a21f1..a9b14ddf888393c736f78fc2eaa7b84f1eaf1495 100644 (file)
@@ -1,3 +1,9 @@
+2014-06-14  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/33101
+       * g++.dg/other/void3.C: New.
+       * g++.dg/conversion/err-recover1.C: Update.
+
 2014-06-13  Peter Bergner  <bergner@vnet.ibm.com>
 
        PR target/61415
index 97237893dc77c8e1919f17416a21226fe9951b1f..4773b1faebe0400ba48781b7472c6494b409cbe5 100644 (file)
@@ -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()
 {
diff --git a/gcc/testsuite/g++.dg/other/void3.C b/gcc/testsuite/g++.dg/other/void3.C
new file mode 100644 (file)
index 0000000..3494d2a
--- /dev/null
@@ -0,0 +1,4 @@
+// PR c++/33101
+
+typedef void v;
+typedef v (*pf)(v);  // { dg-error "invalid use of typedef-name" }