re PR c++/78931 (ICE on C++17 structured bindings from struct with reference member)
authorJakub Jelinek <jakub@redhat.com>
Thu, 5 Jan 2017 21:13:09 +0000 (22:13 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 5 Jan 2017 21:13:09 +0000 (22:13 +0100)
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

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1z/decomp19.C [new file with mode: 0644]

index 5bc7d5217686ac23de21c3222aeab5aefa173577..1d87845a882b33f84668b134c035f621ad5facfd 100644 (file)
@@ -1,5 +1,9 @@
 2017-01-05  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.
+
        PR c++/78890
        * class.c (check_field_decls): Diagnose REFERENCE_TYPE fields in
        unions even for C++11 and later.
index 26c11e261054fd1ceb254d9b227be4da8f313719..75baf94b2d969edbaf83512a5b35a7b9635013f9 100644 (file)
@@ -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;
index c992d7139219c280a2f047f0d290017b830d4334..cd205bd7dd4ffcb49f6e0237a20ecb253d4dc39b 100644 (file)
@@ -1,5 +1,8 @@
 2017-01-05  Jakub Jelinek  <jakub@redhat.com>
 
+       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 (file)
index 0000000..e392e65
--- /dev/null
@@ -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;
+}