Signed-off-by: Mishmish Dev <[email protected]>
---
Hi All,

This fixes the unused warning when an empty structured binding pack is
expanded, by explicitly marking it as read.

Tested on x86_64-pc-linux-gnu.
OK for trunk and gcc-16?

Best,
Mishmish

gcc/cp/ChangeLog:

        PR c++/124977
        * pt.cc (tsubst_pack_expansion): Mark the underlying structured
        binding declaration as read when expanding an empty pack.

gcc/testsuite/ChangeLog:

        PR c++/124977
        * g++.dg/cpp26/decomp-pack-unused.C: New test.

 gcc/cp/pt.cc                                    |  3 +++
 gcc/testsuite/g++.dg/cpp26/decomp-pack-unused.C | 14 ++++++++++++++
 2 files changed, 17 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp26/decomp-pack-unused.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 2a703330173..3b582d882fb 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -14406,6 +14406,9 @@ tsubst_pack_expansion (tree t, tree args, 
tsubst_flags_t complain,
                  if (TREE_VEC_LENGTH (vec))
                    memcpy (TREE_VEC_BEGIN (vec), &TREE_VEC_ELT (arg_pack, 2),
                            TREE_VEC_LENGTH (vec) * sizeof (tree));
+                 else
+                   /* Mark empty binding as read to prevent unused warning.  */
+                   mark_exp_read (TREE_VEC_ELT (arg_pack, 0));
                  arg_pack = make_node (NONTYPE_ARGUMENT_PACK);
                  ARGUMENT_PACK_ARGS (arg_pack) = vec;
                }
diff --git a/gcc/testsuite/g++.dg/cpp26/decomp-pack-unused.C 
b/gcc/testsuite/g++.dg/cpp26/decomp-pack-unused.C
new file mode 100644
index 00000000000..0c63b8d5371
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp26/decomp-pack-unused.C
@@ -0,0 +1,14 @@
+// PR c++/124977
+// { dg-do compile { target c++26 } }
+// { dg-options "-Wall" }
+
+struct Empty {};
+
+void
+foo (auto f, auto value)
+{
+  auto [...args] = value;
+  (..., f (args));
+}
+
+template void foo (int, Empty);

Reply via email to