aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2018-05-29 19:07:57 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2018-05-29 19:07:57 +0200
commit69ce0c8c77e177c138e59d11434676f81425999c (patch)
tree2388274854b71291d640d9534de36845f1f12e08 /gcc
parentfec0bf3084f5d5531fcdc81e13b4813db31a1750 (diff)
downloadgcc-69ce0c8c77e177c138e59d11434676f81425999c.zip
gcc-69ce0c8c77e177c138e59d11434676f81425999c.tar.gz
gcc-69ce0c8c77e177c138e59d11434676f81425999c.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/init.c1
-rw-r--r--gcc/testsuite/ChangeLog3
-rw-r--r--gcc/testsuite/g++.dg/warn/Wunused-var-33.C37
4 files changed, 47 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index a3a443a..d411be5 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 3f1e49b..de1bfee 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 28a2844..d71991f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
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 0000000..080a4f8
--- /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;
+}