]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/85952 (Bogus -Wunused-but-set-variable warning with array structu...
authorJakub Jelinek <jakub@redhat.com>
Fri, 22 Jun 2018 21:27:41 +0000 (23:27 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 22 Jun 2018 21:27:41 +0000 (23:27 +0200)
Backported from mainline
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.

* g++.dg/warn/Wunused-var-33.C: New test.

From-SVN: r261965

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wunused-var-33.C [new file with mode: 0644]

index 9a6c7dc9adb1eae4c29a6f1cefa3acce67d9873f..e32b709acaf7d1f5da39f719edacfba00e239092 100644 (file)
@@ -1,6 +1,12 @@
 2018-06-22  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       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-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/85696
index e9c39ff25e6df09d8bedb454e6949a323ba2e7ed..ec01f6b67760279a8ec47edf5ee83931c7523959 100644 (file)
@@ -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))
            {
index 7669f256a4468a894145de068e5376f90253edd2..55f2c12e8ad5574b61034c4be8a92dd300016cc4 100644 (file)
@@ -6,6 +6,11 @@
        PR c++/85662
        * g++.dg/ext/offsetof3.C: New test.
 
+       2018-05-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/85952
+       * g++.dg/warn/Wunused-var-33.C: New test.
+
        2018-05-11  Jakub Jelinek  <jakub@redhat.com>
 
        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 (file)
index 0000000..5f10d78
--- /dev/null
@@ -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;
+}