[C++] Fix ICE in cp_build_reference_type (PR c++/85076)

Message ID 20180327085202.GU8577@tucnak
State New
Headers show
Series
  • [C++] Fix ICE in cp_build_reference_type (PR c++/85076)
Related show

Commit Message

Jakub Jelinek March 27, 2018, 8:52 a.m.
Hi!

Both build_{reference,pointer}_type start with if (to_type ==
error_mark_node) return error_mark_node;

cp_build_reference_type uses build_reference_type, so in many cases it will
just return error_mark_node if it is passed, but if rval is true, it will
assume build_reference_type returned some REFERENCE_TYPE instead.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2018-03-27  Jakub Jelinek  <jakub@redhat.com>

	PR c++/85076
	* tree.c (cp_build_reference_type): If to_type is error_mark_node,
	return it right away.

	* g++.dg/cpp1y/pr85076.C: New test.


	Jakub

Comments

Jason Merrill March 27, 2018, 7:53 p.m. | #1
OK.

On Tue, Mar 27, 2018 at 4:52 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!

>

> Both build_{reference,pointer}_type start with if (to_type ==

> error_mark_node) return error_mark_node;

>

> cp_build_reference_type uses build_reference_type, so in many cases it will

> just return error_mark_node if it is passed, but if rval is true, it will

> assume build_reference_type returned some REFERENCE_TYPE instead.

>

> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for

> trunk?

>

> 2018-03-27  Jakub Jelinek  <jakub@redhat.com>

>

>         PR c++/85076

>         * tree.c (cp_build_reference_type): If to_type is error_mark_node,

>         return it right away.

>

>         * g++.dg/cpp1y/pr85076.C: New test.

>

> --- gcc/cp/tree.c.jj    2018-03-21 21:18:31.738351376 +0100

> +++ gcc/cp/tree.c       2018-03-26 11:22:47.067967708 +0200

> @@ -1078,6 +1078,9 @@ cp_build_reference_type (tree to_type, b

>  {

>    tree lvalue_ref, t;

>

> +  if (to_type == error_mark_node)

> +    return error_mark_node;

> +

>    if (TREE_CODE (to_type) == REFERENCE_TYPE)

>      {

>        rval = rval && TYPE_REF_IS_RVALUE (to_type);

> --- gcc/testsuite/g++.dg/cpp1y/pr85076.C.jj     2018-03-26 11:26:55.725047985 +0200

> +++ gcc/testsuite/g++.dg/cpp1y/pr85076.C        2018-03-26 11:26:41.807043494 +0200

> @@ -0,0 +1,6 @@

> +// PR c++/85076

> +// { dg-do compile { target c++14 } }

> +

> +template<typename> struct A*;  // { dg-error "expected unqualified-id before" }

> +

> +auto a = [](A<auto>) {};       // { dg-error "is not a template|has incomplete type" }

>

>         Jakub

Patch

--- gcc/cp/tree.c.jj	2018-03-21 21:18:31.738351376 +0100
+++ gcc/cp/tree.c	2018-03-26 11:22:47.067967708 +0200
@@ -1078,6 +1078,9 @@  cp_build_reference_type (tree to_type, b
 {
   tree lvalue_ref, t;
 
+  if (to_type == error_mark_node)
+    return error_mark_node;
+
   if (TREE_CODE (to_type) == REFERENCE_TYPE)
     {
       rval = rval && TYPE_REF_IS_RVALUE (to_type);
--- gcc/testsuite/g++.dg/cpp1y/pr85076.C.jj	2018-03-26 11:26:55.725047985 +0200
+++ gcc/testsuite/g++.dg/cpp1y/pr85076.C	2018-03-26 11:26:41.807043494 +0200
@@ -0,0 +1,6 @@ 
+// PR c++/85076
+// { dg-do compile { target c++14 } }
+
+template<typename> struct A*;	// { dg-error "expected unqualified-id before" }
+
+auto a = [](A<auto>) {};	// { dg-error "is not a template|has incomplete type" }