This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH] Fix decomp handling of fields with reference type (PR c++/78931)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 4 Jan 2017 23:06:43 +0100
- Subject: Re: [C++ PATCH] Fix decomp handling of fields with reference type (PR c++/78931)
- Authentication-results: sourceware.org; auth=none
- References: <20161229151130.GN21933@tucnak> <CADzB+2nTh2MpmfPZfYDj8WnKohyRfW9+h3zODKzWBV8OVnXMow@mail.gmail.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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