diff options
author | Jason Merrill <jason@redhat.com> | 2025-03-22 10:52:14 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2025-03-24 13:03:18 -0400 |
commit | 94d1dacf350c3c463aead7e4d5c172f138045eb1 (patch) | |
tree | 3e6fd12d51a06f62fffe4330b8f08932507a3b79 | |
parent | 57fdc97dac1453849a76bdce265428d441a03de0 (diff) | |
download | gcc-94d1dacf350c3c463aead7e4d5c172f138045eb1.zip gcc-94d1dacf350c3c463aead7e4d5c172f138045eb1.tar.gz gcc-94d1dacf350c3c463aead7e4d5c172f138045eb1.tar.bz2 |
c++: pack indexing and if consteval
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.
-rw-r--r-- | gcc/cp/semantics.cc | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp26/pack-indexing16.C | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index b0a5f9a..b390d66 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -5086,7 +5086,7 @@ finish_underlying_type (tree type) 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) diff --git a/gcc/testsuite/g++.dg/cpp26/pack-indexing16.C b/gcc/testsuite/g++.dg/cpp26/pack-indexing16.C new file mode 100644 index 0000000..92ade86 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/pack-indexing16.C @@ -0,0 +1,16 @@ +// { 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>(); +} |