https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124198
--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-15 branch has been updated by Jakub Jelinek <[email protected]>: https://gcc.gnu.org/g:b9dc77aec36743ba7acbd193c13c3356b0b4daaf commit r15-11213-gb9dc77aec36743ba7acbd193c13c3356b0b4daaf Author: Jakub Jelinek <[email protected]> Date: Sat Apr 4 11:07:40 2026 +0200 c++: Fix up pack indexing [PR124198] https://eel.is/c++draft/expr.prim.pack.index#2 says: The constant-expression shall be a converted constant expression of type std::size_t whose value V, termed the index, is such that 0<=V<sizeof...(P). But we actually don't implement it like that, instead just error out if the index doesn't have an integral type or is negative. Because of this we don't call mark_rvalue_use on it, so on pack-indexing20.C we report a bogus warning that the var used in the index is unused but set, and more importantly we reject the IMHO valid testcase pack-indexing21.C. The following patch calls build_converted_constant_expr to make sure it is converted, marked as read, if not possible to be converted diagnostics is emitted. 2026-04-04 Jakub Jelinek <[email protected]> PR c++/124198 * parser.cc (cp_parser_pack_index): If index is not type dependent, call build_converted_constant_expr on it. Return error_mark_node if index is error_operand_p. * pt.cc (tsubst_pack_index): Likewise. * g++.dg/cpp26/pack-indexing2.C (getT2, badtype4): Expect different diagnostics. * g++.dg/cpp26/pack-indexing20.C: New test. * g++.dg/cpp26/pack-indexing21.C: New test. (cherry picked from commit 647cbb7812ed77a1b39c41dcacc8f30626087a95)
