From: Jakub Jelinek Date: Thu, 5 Jan 2017 21:13:09 +0000 (+0100) Subject: re PR c++/78931 (ICE on C++17 structured bindings from struct with reference member) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=26f203712b9a90913473a1a75ce6f96783a6ec65;p=gcc.git re PR c++/78931 (ICE on C++17 structured bindings from struct with reference member) 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. From-SVN: r244113 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5bc7d521768..1d87845a882 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2017-01-05 Jakub Jelinek + PR c++/78931 + * decl.c (cp_finish_decomp): Remove probe variable, if tt is + REFERENCE_REF_P, set tt to its operand. + PR c++/78890 * class.c (check_field_decls): Diagnose REFERENCE_TYPE fields in unions even for C++11 and later. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 26c11e26105..75baf94b2d9 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7593,10 +7593,9 @@ cp_finish_decomp (tree decl, tree first, unsigned int count) 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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c992d713921..cd205bd7dd4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2017-01-05 Jakub Jelinek + PR c++/78931 + * g++.dg/cpp1z/decomp19.C: New test. + PR c++/78890 * g++.dg/init/ref14.C: Expect error even in C++11 and later. * g++.dg/init/union1.C: Likewise. diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp19.C b/gcc/testsuite/g++.dg/cpp1z/decomp19.C new file mode 100644 index 00000000000..e392e658e27 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/decomp19.C @@ -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; +}