diff mbox series

C++ PATCH for c++/86915, ICE with auto[]

Message ID 20180811165310.GM4317@redhat.com
State New
Headers show
Series C++ PATCH for c++/86915, ICE with auto[] | expand

Commit Message

Marek Polacek Aug. 11, 2018, 4:53 p.m. UTC
This fixes ICE-on-invalid with an array of auto.  The problem was that
create_array_type_for_decl got null name, so the error call crashed.  We
need to handle this case as elsewhere in the function.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-08-11  Marek Polacek  <polacek@redhat.com>

	PR c++/86915
	* decl.c (create_array_type_for_decl): Handle null name.

	* g++.dg/diagnostic/auto1.C: New test.

Comments

Jason Merrill Aug. 13, 2018, 6:28 a.m. UTC | #1
OK.

On Sun, Aug 12, 2018 at 4:53 AM, Marek Polacek <polacek@redhat.com> wrote:
> This fixes ICE-on-invalid with an array of auto.  The problem was that
> create_array_type_for_decl got null name, so the error call crashed.  We
> need to handle this case as elsewhere in the function.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2018-08-11  Marek Polacek  <polacek@redhat.com>
>
>         PR c++/86915
>         * decl.c (create_array_type_for_decl): Handle null name.
>
>         * g++.dg/diagnostic/auto1.C: New test.
>
> --- gcc/cp/decl.c
> +++ gcc/cp/decl.c
> @@ -9838,7 +9838,10 @@ create_array_type_for_decl (tree name, tree type, tree size)
>       type-specifier, the program is ill-formed.  */
>    if (type_uses_auto (type))
>      {
> -      error ("%qD declared as array of %qT", name, type);
> +      if (name)
> +   error ("%qD declared as array of %qT", name, type);
> +      else
> +   error ("creating array of %qT", type);
>        return error_mark_node;
>      }
>
> --- gcc/testsuite/g++.dg/diagnostic/auto1.C
> +++ gcc/testsuite/g++.dg/diagnostic/auto1.C
> @@ -0,0 +1,4 @@
> +// PR c++/86915
> +// { dg-do compile { target c++17 } }
> +
> +template<auto [1]> struct S; // { dg-error "creating array of .auto." }
diff mbox series

Patch

--- gcc/cp/decl.c
+++ gcc/cp/decl.c
@@ -9838,7 +9838,10 @@  create_array_type_for_decl (tree name, tree type, tree size)
      type-specifier, the program is ill-formed.  */
   if (type_uses_auto (type))
     {
-      error ("%qD declared as array of %qT", name, type);
+      if (name)
+   error ("%qD declared as array of %qT", name, type);
+      else
+   error ("creating array of %qT", type);
       return error_mark_node;
     }
 
--- gcc/testsuite/g++.dg/diagnostic/auto1.C
+++ gcc/testsuite/g++.dg/diagnostic/auto1.C
@@ -0,0 +1,4 @@ 
+// PR c++/86915
+// { dg-do compile { target c++17 } }
+
+template<auto [1]> struct S; // { dg-error "creating array of .auto." }