From: Jakub Jelinek Date: Fri, 15 Dec 2017 19:41:45 +0000 (+0100) Subject: re PR c++/83217 (Compiler segfault: structured binding by reference to a templated... X-Git-Tag: basepoints/gcc-9~2638 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3a661b45e8d9baf96bef773e214f4c41581bc22;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 25d7f58ea581..1108aeb890c0 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 63a7b92b3bc8..5df16bb21bfc 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 3d037b53d9d0..cd208ff1a7ff 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 000000000000..6429108dd7c4 --- /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 } } +}