From: Paolo Carlini Date: Mon, 9 Apr 2018 22:33:35 +0000 (+0000) Subject: re PR c++/85227 (ICE with structured binding of a forward declared variable) X-Git-Tag: upstream/12.2.0~32415 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=52912c916051945e8474966937bf79ae48fefabe;p=platform%2Fupstream%2Fgcc.git 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c8eae2e..33f0c37 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 d55c2b7..44a152b 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 9bfd591..260150c 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 0000000..168a13e --- /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 0000000..27874fb --- /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>(); +}