]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/83217 (Compiler segfault: structured binding by reference to a templated...
authorJakub Jelinek <jakub@redhat.com>
Fri, 15 Dec 2017 19:41:45 +0000 (20:41 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 15 Dec 2017 19:41:45 +0000 (20:41 +0100)
PR c++/83217
* decl.c (cp_finish_decomp): If decl's type is REFERENCE_TYPE,
call complete_type (TREE_TYPE (type)).

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

From-SVN: r255702

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

index 25d7f58ea5816b8d4032e187dcb18ac52009b7da..1108aeb890c00646898191df859a5f9602b91632 100644 (file)
@@ -1,5 +1,9 @@
 2017-12-15  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/83217
+       * decl.c (cp_finish_decomp): If decl's type is REFERENCE_TYPE,
+       call complete_type (TREE_TYPE (type)).
+
        * tree.c (cxx_attribute_table, std_attribute_table): Swap
        affects_type_identity and handler fields, adjust comments.
 
index 63a7b92b3bc871f534f125fcde4b10929ccce1d7..5df16bb21bfc8b63c275071a004e69df116fe217 100644 (file)
@@ -7404,7 +7404,9 @@ cp_finish_decomp (tree decl, tree first, unsigned int count)
   if (TREE_CODE (type) == REFERENCE_TYPE)
     {
       dexp = convert_from_reference (dexp);
-      type = TREE_TYPE (type);
+      type = complete_type (TREE_TYPE (type));
+      if (type == error_mark_node)
+       goto error_out;
     }
 
   tree eltype = NULL_TREE;
index 3d037b53d9d0f0a94e3d3917c45ea919baad531b..cd208ff1a7ff335352bb744d533376279370a0a4 100644 (file)
@@ -1,5 +1,8 @@
 2017-12-15  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/83217
+       * g++.dg/cpp1z/decomp33.C: New test.
+
        PR tree-optimization/80631
        * gcc.target/i386/avx2-pr80631.c: New test.
 
diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp33.C b/gcc/testsuite/g++.dg/cpp1z/decomp33.C
new file mode 100644 (file)
index 0000000..6429108
--- /dev/null
@@ -0,0 +1,21 @@
+// PR c++/83217
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+template <typename T>
+struct S
+{
+  T a;
+};
+
+void
+foo (S<int> *b)
+{
+  auto & [c] = *b;     // { dg-warning "structured bindings only available with" "" { target c++14_down } }
+}
+
+void
+bar (S<char> *d)
+{
+  auto [e] = *d;       // { dg-warning "structured bindings only available with" "" { target c++14_down } }
+}