]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: cv-qualified pack index propagation [PR122169]
authorPatrick Palka <ppalka@redhat.com>
Thu, 5 Feb 2026 14:13:42 +0000 (09:13 -0500)
committerPatrick Palka <ppalka@redhat.com>
Thu, 5 Feb 2026 14:13:42 +0000 (09:13 -0500)
Since type pack indexes can be cv-qualified, we need to propagate their
qualifiers when substituting them.

PR c++/122169

gcc/cp/ChangeLog:

* pt.cc (tsubst_pack_index): Propagate cv-qualifiers of
PACK_INDEX_TYPE.

gcc/testsuite/ChangeLog:

* g++.dg/cpp26/pack-indexing19.C: New test.

Reviewed-by: Marek Polacek <polacek@redhat.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp26/pack-indexing19.C [new file with mode: 0644]

index 1ee8e2fff7df2e0edd3da6838b205c03a34ced6f..08c6b42ef05ba0389af4c4af9c6f51b80c962fc4 100644 (file)
@@ -14368,10 +14368,15 @@ tsubst_pack_index (tree t, tree args, tsubst_flags_t complain, tree in_decl)
   tree index = tsubst_expr (PACK_INDEX_INDEX (t), args, complain, in_decl);
   const bool parenthesized_p = (TREE_CODE (t) == PACK_INDEX_EXPR
                                && PACK_INDEX_PARENTHESIZED_P (t));
+  tree r;
   if (!value_dependent_expression_p (index) && TREE_CODE (pack) == TREE_VEC)
-    return pack_index_element (index, pack, parenthesized_p, complain);
+    r = pack_index_element (index, pack, parenthesized_p, complain);
   else
-    return make_pack_index (pack, index);
+    r = make_pack_index (pack, index);
+  if (TREE_CODE (t) == PACK_INDEX_TYPE)
+    r = cp_build_qualified_type (r, cp_type_quals (t) | cp_type_quals (r),
+                                complain | tf_ignore_bad_quals);
+  return r;
 }
 
 /* Make an argument pack out of the TREE_VEC VEC.  */
diff --git a/gcc/testsuite/g++.dg/cpp26/pack-indexing19.C b/gcc/testsuite/g++.dg/cpp26/pack-indexing19.C
new file mode 100644 (file)
index 0000000..cd93705
--- /dev/null
@@ -0,0 +1,32 @@
+// PR c++/122169
+// { dg-do compile { target c++26 } }
+
+template<class T, class U>
+concept same_as = __is_same(T, U);
+
+template<class... Ts>
+void f() {
+  using T = Ts...[0];
+  static_assert(same_as<const T, const int>);
+
+  []<int I>() {
+    using U = Ts...[I];
+    static_assert(same_as<const U, const int>);
+  }.template operator()<0>();
+}
+
+template void f<int>();
+
+
+template<class... Ts>
+void g() {
+  using T = Ts...[0];
+  static_assert(same_as<const T, const volatile int>);
+
+  []<int I>() {
+    using U = Ts...[I];
+    static_assert(same_as<const U, const volatile int>);
+  }.template operator()<0>();
+}
+
+template void g<volatile int>();