This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On Wed, Jan 04, 2017 at 04:27:42PM -0500, Jason Merrill wrote:
> 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.

Like this?  Ok for trunk if bootstrap/regtest passes (just started them;
make check-c++-all didn't show regressions)?

2017-01-04  Jakub Jelinek  <jakub@redhat.com>

	PR c++/78931
	* decl.c (cp_finish_decomp): Remove probe variable, if tt is
	REFERENCE_REF_P, set tt to its operand.

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

--- gcc/cp/decl.c.jj	2017-01-01 12:45:44.562588381 +0100
+++ gcc/cp/decl.c	2017-01-04 22:39:07.704107521 +0100
@@ -7593,10 +7593,9 @@ cp_finish_decomp (tree decl, tree first,
 	else
 	  {
 	    tree tt = finish_non_static_data_member (field, t, NULL_TREE);
-	    tree probe = tt;
-	    if (REFERENCE_REF_P (probe))
-	      probe = TREE_OPERAND (probe, 0);
-	    TREE_TYPE (v[i]) = TREE_TYPE (probe);
+	    if (REFERENCE_REF_P (tt))
+	      tt = TREE_OPERAND (tt, 0);
+	    TREE_TYPE (v[i]) = TREE_TYPE (tt);
 	    layout_decl (v[i], 0);
 	    SET_DECL_VALUE_EXPR (v[i], tt);
 	    DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
--- gcc/testsuite/g++.dg/cpp1z/decomp19.C.jj	2017-01-04 22:37:28.737355629 +0100
+++ gcc/testsuite/g++.dg/cpp1z/decomp19.C	2017-01-04 22:37:28.737355629 +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;
+}


	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]