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
This commit is contained in:
Jakub Jelinek 2018-05-29 19:07:57 +02:00 committed by Jakub Jelinek
parent fec0bf3084
commit 69ce0c8c77
4 changed files with 47 additions and 0 deletions

View File

@ -1,3 +1,9 @@
2018-05-29 Jakub Jelinek <jakub@redhat.com>
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 <bernd.edlinger@hotmail.de>
* decl2.c (start_static_storage_duration_function): Use

View File

@ -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))
{

View File

@ -1,5 +1,8 @@
2018-05-29 Jakub Jelinek <jakub@redhat.com>
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

View File

@ -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;
}