The pack index is manifestly constant-evaluated, and the call to
maybe_constant_value needs to reflect that or we wrongly complain about
non-constant index if the evaluation uses if consteval.
gcc/cp/ChangeLog:
* semantics.cc (finish_type_pack_element): Pass mce_true to
maybe_constant_value.
gcc/testsuite/ChangeLog:
* g++.dg/cpp26/pack-indexing16.C: New test.
static tree
finish_type_pack_element (tree idx, tree types, tsubst_flags_t complain)
{
- idx = maybe_constant_value (idx);
+ idx = maybe_constant_value (idx, NULL_TREE, mce_true);
if (TREE_CODE (idx) != INTEGER_CST || !INTEGRAL_TYPE_P (TREE_TYPE (idx)))
{
if (complain & tf_error)
--- /dev/null
+// { dg-do compile { target c++26 } }
+
+int i;
+constexpr int idx()
+{
+ if consteval { return 0; }
+ else { return i; }
+}
+
+template <int... Ns>
+int first () { return Ns...[idx()]; }
+
+int main()
+{
+ return first<0,1,2>();
+}