]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: pack indexing is a non-deduced context [PR121795]
authorPatrick Palka <ppalka@redhat.com>
Fri, 12 Sep 2025 18:21:25 +0000 (14:21 -0400)
committerPatrick Palka <ppalka@redhat.com>
Fri, 12 Sep 2025 18:21:25 +0000 (14:21 -0400)
We weren't explicitly treating a pack index specifier as a non-deduced
context (as per [temp.deduct.type]/5), leading to an ICE for the first
testcase below.

PR c++/121795

gcc/cp/ChangeLog:

* pt.cc (unify) <case PACK_INDEX_TYPE>: New non-deduced context
case.

gcc/testsuite/ChangeLog:

* g++.dg/cpp26/pack-indexing17.C: New test.
* g++.dg/cpp26/pack-indexing17a.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-indexing17.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp26/pack-indexing17a.C [new file with mode: 0644]

index 7f0d16f217e7ee296854a43e465a0a22eac76b33..b7cb807d8daa3014d24f02e2a3d8f473afb223b2 100644 (file)
@@ -26301,8 +26301,8 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict,
     case TYPEOF_TYPE:
     case DECLTYPE_TYPE:
     case TRAIT_TYPE:
-      /* Cannot deduce anything from TYPEOF_TYPE, DECLTYPE_TYPE,
-        or TRAIT_TYPE nodes.  */
+    case PACK_INDEX_TYPE:
+      /* These are non-deduced contexts.  */
       return unify_success (explain_p);
 
     case ERROR_MARK:
diff --git a/gcc/testsuite/g++.dg/cpp26/pack-indexing17.C b/gcc/testsuite/g++.dg/cpp26/pack-indexing17.C
new file mode 100644 (file)
index 0000000..8450ed6
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/121795
+// { dg-do compile { target c++26 } }
+
+template<class T, class... Ts>
+struct A;
+
+template<class... Ts>
+struct A<Ts...[sizeof...(Ts)-1], Ts...> { };
+
+A<int, int> x;
+A<char, int> y; // { dg-error "incomplete" }
diff --git a/gcc/testsuite/g++.dg/cpp26/pack-indexing17a.C b/gcc/testsuite/g++.dg/cpp26/pack-indexing17a.C
new file mode 100644 (file)
index 0000000..445f0d9
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/121795
+// A version of pack-indexing17.C using a nontype pack.
+// { dg-do compile { target c++26 } }
+
+template<int N, int... Ns>
+struct A;
+
+template<int... Ns>
+struct A<Ns...[sizeof...(Ns)-1], Ns...> { };
+
+A<0, 0> x;
+A<0, 1> y; // { dg-error "incomplete" }