From: Jakub Jelinek Date: Fri, 22 Jun 2018 21:27:41 +0000 (+0200) Subject: backport: re PR c++/85952 (Bogus -Wunused-but-set-variable warning with array structu... X-Git-Tag: releases/gcc-7.4.0~324 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d500ed580819f3c1a274b6a01688aef22d7b066;p=thirdparty%2Fgcc.git backport: re PR c++/85952 (Bogus -Wunused-but-set-variable warning with array structured binding) Backported from mainline 2018-05-29 Jakub Jelinek PR c++/85952 * init.c (build_aggr_init): For structured binding initialized from array call mark_rvalue_use on the initializer. * g++.dg/warn/Wunused-var-33.C: New test. From-SVN: r261965 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9a6c7dc9adb1..e32b709acaf7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,6 +1,12 @@ 2018-06-22 Jakub Jelinek Backported from mainline + 2018-05-29 Jakub Jelinek + + PR c++/85952 + * init.c (build_aggr_init): For structured binding initialized from + array call mark_rvalue_use on the initializer. + 2018-05-11 Jakub Jelinek PR c/85696 diff --git a/gcc/cp/init.c b/gcc/cp/init.c index e9c39ff25e6d..ec01f6b67760 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1632,6 +1632,7 @@ build_aggr_init (tree exp, tree init, int flags, tsubst_flags_t complain) if (VAR_P (exp) && DECL_DECOMPOSITION_P (exp)) { from_array = 1; + init = mark_rvalue_use (init); if (init && DECL_P (init) && !(flags & LOOKUP_ONLYCONVERTING)) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7669f256a446..55f2c12e8ad5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -6,6 +6,11 @@ PR c++/85662 * g++.dg/ext/offsetof3.C: New test. + 2018-05-29 Jakub Jelinek + + PR c++/85952 + * g++.dg/warn/Wunused-var-33.C: New test. + 2018-05-11 Jakub Jelinek PR c/85696 diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-33.C b/gcc/testsuite/g++.dg/warn/Wunused-var-33.C new file mode 100644 index 000000000000..5f10d7810821 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-33.C @@ -0,0 +1,37 @@ +// PR c++/85952 +// { dg-do compile { target c++11 } } +// { dg-options "-Wunused-but-set-variable" } + +int +foo () +{ + int a[2] = {1, 2}; // { dg-bogus "set but not used" } */ + auto [x, y] = a; // { dg-warning "decomposition declaration only available with" "" { target c++14_down } } + return x + y; +} + +struct S { int d, e; }; + +int +bar () +{ + S a = {1, 2}; + auto [x, y] = a; // { dg-warning "decomposition declaration only available with" "" { target c++14_down } } + return x + y; +} + +int +baz () +{ + S a = {1, 2}; + auto & [x, y] = a; // { dg-warning "decomposition declaration only available with" "" { target c++14_down } } + return x + y; +} + +int +qux () +{ + int a[2] = {1, 2}; + auto & [x, y] = a; // { dg-warning "decomposition declaration only available with" "" { target c++14_down } } + return x + y; +}