From e3a661b45e8d9baf96bef773e214f4c41581bc22 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 15 Dec 2017 20:41:45 +0100 Subject: [PATCH] re PR c++/83217 (Compiler segfault: structured binding by reference to a templated type via a pointer) 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 | 4 ++++ gcc/cp/decl.c | 4 +++- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/cpp1z/decomp33.C | 21 +++++++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/decomp33.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 25d7f58ea58..1108aeb890c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2017-12-15 Jakub Jelinek + 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. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 63a7b92b3bc..5df16bb21bf 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3d037b53d9d..cd208ff1a7f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2017-12-15 Jakub Jelinek + 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 index 00000000000..6429108dd7c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/decomp33.C @@ -0,0 +1,21 @@ +// PR c++/83217 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +template +struct S +{ + T a; +}; + +void +foo (S *b) +{ + auto & [c] = *b; // { dg-warning "structured bindings only available with" "" { target c++14_down } } +} + +void +bar (S *d) +{ + auto [e] = *d; // { dg-warning "structured bindings only available with" "" { target c++14_down } } +} -- 2.30.2