From 69ce0c8c77e177c138e59d11434676f81425999c Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 29 May 2018 19:07:57 +0200 Subject: [PATCH] re PR c++/85952 (Bogus -Wunused-but-set-variable warning with array structured binding) 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: r260899 --- gcc/cp/ChangeLog | 6 ++++ gcc/cp/init.c | 1 + gcc/testsuite/ChangeLog | 3 ++ gcc/testsuite/g++.dg/warn/Wunused-var-33.C | 37 ++++++++++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-33.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a3a443a69b9..d411be5d9d8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +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-28 Bernd Edlinger * decl2.c (start_static_storage_duration_function): Use diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 3f1e49bae21..de1bfee54bb 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1678,6 +1678,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 28a28448741..d71991fb646 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2018-05-29 Jakub Jelinek + PR c++/85952 + * g++.dg/warn/Wunused-var-33.C: New test. + PR target/85918 * gcc.target/i386/avx512dq-pr85918.c: Add -mprefer-vector-width=512 and -fno-vect-cost-model options. Add aligned(64) attribute to the 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 00000000000..080a4f81d72 --- /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 "structured bindings 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 "structured bindings only available with" "" { target c++14_down } } + return x + y; +} + +int +baz () +{ + S a = {1, 2}; + auto & [x, y] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } } + return x + y; +} + +int +qux () +{ + int a[2] = {1, 2}; + auto & [x, y] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } } + return x + y; +} -- 2.30.2