From 52912c916051945e8474966937bf79ae48fefabe Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 9 Apr 2018 22:33:35 +0000 Subject: [PATCH] re PR c++/85227 (ICE with structured binding of a forward declared variable) /cp 2018-04-09 Paolo Carlini PR c++/85227 * decl.c (cp_finish_decomp): In a template, if the type is incomplete issue a pedwarn and defer trying to do bindings. /testsuite 2018-04-09 Paolo Carlini PR c++/85227 * g++.dg/cpp1z/decomp44.C: New. * g++.dg/cpp1z/decomp45.C: Likewise. From-SVN: r259259 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl.c | 3 +++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/cpp1z/decomp44.C | 10 ++++++++++ gcc/testsuite/g++.dg/cpp1z/decomp45.C | 18 ++++++++++++++++++ 5 files changed, 43 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp1z/decomp44.C create mode 100644 gcc/testsuite/g++.dg/cpp1z/decomp45.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c8eae2ef179..33f0c37a3cd 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-04-09 Paolo Carlini + + PR c++/85227 + * decl.c (cp_finish_decomp): In a template, if the type is incomplete + issue a pedwarn and defer trying to do bindings. + 2018-04-09 Jason Merrill PR c++/85279 - dump_expr doesn't understand decltype. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index d55c2b70c0e..44a152bd195 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7756,6 +7756,9 @@ cp_finish_decomp (tree decl, tree first, unsigned int count) error_at (loc, "cannot decompose lambda closure type %qT", type); goto error_out; } + else if (processing_template_decl && !COMPLETE_TYPE_P (type)) + pedwarn (loc, 0, "structured binding refers to incomplete class type %qT", + type); else { tree btype = find_decomp_class_base (loc, type, NULL_TREE); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9bfd5915ed1..260150c3da2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-04-09 Paolo Carlini + + PR c++/85227 + * g++.dg/cpp1z/decomp44.C: New. + * g++.dg/cpp1z/decomp45.C: Likewise. + 2018-04-09 Thomas Koenig PR fortran/83064 diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp44.C b/gcc/testsuite/g++.dg/cpp1z/decomp44.C new file mode 100644 index 00000000000..168a13e0dc9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/decomp44.C @@ -0,0 +1,10 @@ +// PR c++/85227 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +extern struct A a; + +template void foo() +{ + auto[i] = a; // { dg-warning "incomplete" } +} // { dg-warning "structured bindings only available with -std=c..17 or -std=gnu..17" "" { target c++14_down } .-1 } diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp45.C b/gcc/testsuite/g++.dg/cpp1z/decomp45.C new file mode 100644 index 00000000000..27874fbdfc4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/decomp45.C @@ -0,0 +1,18 @@ +// PR c++/85227 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +extern struct A a; + +template +void f() +{ + auto [x] = a; // { dg-warning "incomplete" } +} // { dg-warning "structured bindings only available with -std=c..17 or -std=gnu..17" "" { target c++14_down } .-1 } + +struct A { int i; }; + +int main() +{ + f<0>(); +} -- 2.30.2