diff mbox

[C++] Fix decomp handling of fields with reference type (PR c++/78931)

Message ID 20161229151130.GN21933@tucnak
State New
Headers show

Commit Message

Jakub Jelinek Dec. 29, 2016, 3:11 p.m. UTC
Hi!

When a field has reference type, we correctly used the reference type as the
type of the var with value expr, but the DECL_VALUE_EXPR had the type/value after
convert_from_reference, which leads to invalid IL.

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

2016-12-29  Jakub Jelinek  <jakub@redhat.com>

	PR c++/78931
	* decl.c (cp_finish_decomp): SET_DECL_VALUE_EXPR to probe rather than
	tt.

	* g++.dg/cpp1z/decomp19.C: New test.


	Jakub

Comments

Jason Merrill Jan. 4, 2017, 9:27 p.m. UTC | #1
On Thu, Dec 29, 2016 at 10:11 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>               probe = TREE_OPERAND (probe, 0);
>             TREE_TYPE (v[i]) = TREE_TYPE (probe);
>             layout_decl (v[i], 0);
> -           SET_DECL_VALUE_EXPR (v[i], tt);
> +           SET_DECL_VALUE_EXPR (v[i], probe);

I guess we can do away with the probe variable and change tt instead.

Jason
diff mbox

Patch

--- gcc/cp/decl.c.jj	2016-12-21 22:57:08.000000000 +0100
+++ gcc/cp/decl.c	2016-12-28 13:16:45.294616666 +0100
@@ -7598,7 +7598,7 @@  cp_finish_decomp (tree decl, tree first,
 	      probe = TREE_OPERAND (probe, 0);
 	    TREE_TYPE (v[i]) = TREE_TYPE (probe);
 	    layout_decl (v[i], 0);
-	    SET_DECL_VALUE_EXPR (v[i], tt);
+	    SET_DECL_VALUE_EXPR (v[i], probe);
 	    DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
 	    i++;
 	  }
--- gcc/testsuite/g++.dg/cpp1z/decomp19.C.jj	2016-12-28 13:18:27.093305954 +0100
+++ gcc/testsuite/g++.dg/cpp1z/decomp19.C	2016-12-28 13:18:19.000000000 +0100
@@ -0,0 +1,13 @@ 
+// PR c++/78931
+// { dg-do run { target c++11 } }
+// { dg-options "" }
+
+int
+main ()
+{
+  int x = 99;
+  struct S { int &x; };
+  S s{x};
+  auto [p] = s;		// { dg-warning "decomposition declaration only available with" "" { target c++14_down } }
+  return p - 99;
+}