Find a file
Marek Polacek c435272166 c++: Implement P2662R3, Pack Indexing [PR113798]
This patch implements C++26 Pack Indexing, as described in
<https://wg21.link/P2662R3>.

The issue discussing how to mangle pack indexes has not been resolved
yet <https://github.com/itanium-cxx-abi/cxx-abi/issues/175> and I've
made no attempt to address it so far.

Unlike v1, which used augmented TYPE/EXPR_PACK_EXPANSION codes, this
version introduces two new codes: PACK_INDEX_EXPR and PACK_INDEX_TYPE.
Both carry two operands: the pack expansion and the index.  They are
handled in tsubst_pack_index: substitute the index and the pack and
then extract the element from the vector (if possible).

To handle pack indexing in a decltype or with decltype(auto), there is
also the new PACK_INDEX_PARENTHESIZED_P flag.

With this feature, it's valid to write something like

  using U = tmpl<Ts...[Is]...>;

where we first expand the template argument into

  Ts...[Is#0], Ts...[Is#1], ...

and then substitute each individual pack index.

	PR c++/113798

gcc/cp/ChangeLog:

	* constexpr.cc (potential_constant_expression_1) <case PACK_INDEX_EXPR>:
	New case.
	* cp-objcp-common.cc (cp_common_init_ts): Mark PACK_INDEX_TYPE and
	PACK_INDEX_EXPR.
	* cp-tree.def (PACK_INDEX_TYPE): New.
	(PACK_INDEX_EXPR): New.
	* cp-tree.h (WILDCARD_TYPE_P): Also check PACK_INDEX_TYPE.
	(PACK_INDEX_CHECK): Define.
	(PACK_INDEX_P): Define.
	(PACK_INDEX_PACK): Define.
	(PACK_INDEX_INDEX): Define.
	(PACK_INDEX_PARENTHESIZED_P): Define.
	(make_pack_index): Declare.
	(pack_index_element): Declare.
	* cxx-pretty-print.cc (cxx_pretty_printer::expression) <case
	PACK_INDEX_EXPR>: New case.
	(cxx_pretty_printer::type_id) <case PACK_INDEX_TYPE>: New case.
	* error.cc (dump_type) <case PACK_INDEX_TYPE>: New case.
	(dump_type_prefix): Handle PACK_INDEX_TYPE.
	(dump_type_suffix): Likewise.
	(dump_expr) <case PACK_INDEX_EXPR>: New case.
	* mangle.cc (write_type) <case PACK_INDEX_TYPE>: New case.
	* module.cc (trees_out::type_node) <case PACK_INDEX_TYPE>: New case.
	(trees_in::tree_node) <case PACK_INDEX_TYPE>: New case.
	* parser.cc (cp_parser_next_tokens_are_pack_index_p): New.
	(cp_parser_pack_index): New.
	(cp_parser_primary_expression): Handle a C++26 pack-index-expression.
	(cp_parser_unqualified_id): Handle a C++26 pack-index-specifier.
	(cp_parser_nested_name_specifier_opt): See if a pack-index-specifier
	follows.
	(cp_parser_qualifying_entity): Handle a C++26 pack-index-specifier.
	(cp_parser_decltype_expr): Set id_expression_or_member_access_p for
	pack indexing.
	(cp_parser_mem_initializer_id): Handle a C++26 pack-index-specifier.
	(cp_parser_simple_type_specifier): Likewise.
	(cp_parser_base_specifier): Likewise.
	* pt.cc (iterative_hash_template_arg) <case PACK_INDEX_TYPE,
	PACK_INDEX_EXPR>: New case.
	(find_parameter_packs_r) <case PACK_INDEX_TYPE, PACK_INDEX_EXPR>: New
	case.
	(make_pack_index): New.
	(tsubst_pack_index): New.
	(tsubst): Avoid tsubst on PACK_INDEX_TYPE.
	<case TYPENAME_TYPE>: Add a call to error.
	<case PACK_INDEX_TYPE>: New case.
	(tsubst_expr) <case PACK_INDEX_EXPR>: New case.
	(dependent_type_p_r): Return true for PACK_INDEX_TYPE.
	(type_dependent_expression_p): Recurse on PACK_INDEX_PACK for
	PACK_INDEX_EXPR.
	* ptree.cc (cxx_print_type) <case PACK_INDEX_TYPE>: New case.
	* semantics.cc (finish_parenthesized_expr): Set
	PACK_INDEX_PARENTHESIZED_P for PACK_INDEX_EXPR.
	(finish_type_pack_element): Adjust error messages.
	(pack_index_element): New.
	* tree.cc (cp_tree_equal) <case PACK_INDEX_EXPR>: New case.
	(cp_walk_subtrees) <case PACK_INDEX_TYPE, PACK_INDEX_EXPR>: New case.
	* typeck.cc (structural_comptypes) <case PACK_INDEX_TYPE>: New case.

libstdc++-v3/ChangeLog:

	* testsuite/20_util/tuple/element_access/get_neg.cc: Adjust
	dg-prune-output.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp26/pack-indexing1.C: New test.
	* g++.dg/cpp26/pack-indexing2.C: New test.
	* g++.dg/cpp26/pack-indexing3.C: New test.
	* g++.dg/cpp26/pack-indexing4.C: New test.
	* g++.dg/cpp26/pack-indexing5.C: New test.
	* g++.dg/cpp26/pack-indexing6.C: New test.
	* g++.dg/cpp26/pack-indexing7.C: New test.
	* g++.dg/cpp26/pack-indexing8.C: New test.
	* g++.dg/cpp26/pack-indexing9.C: New test.
	* g++.dg/cpp26/pack-indexing10.C: New test.
	* g++.dg/cpp26/pack-indexing11.C: New test.
	* g++.dg/modules/pack-index-1_a.C: New test.
	* g++.dg/modules/pack-index-1_b.C: New test.
2024-11-28 10:16:46 -05:00
.forgejo top-level: Add pull request template for Forgejo 2024-10-23 19:45:09 +01:00
.github Minor formatting fix for newly-added file from previous commit 2023-11-01 19:28:56 -04:00
c++tools Daily bump. 2024-05-09 10:58:01 +00:00
config Daily bump. 2024-11-26 00:19:26 +00:00
contrib Daily bump. 2024-11-26 00:19:26 +00:00
fixincludes Daily bump. 2024-07-12 00:17:52 +00:00
gcc c++: Implement P2662R3, Pack Indexing [PR113798] 2024-11-28 10:16:46 -05:00
gnattools Daily bump. 2024-07-08 00:17:01 +00:00
gotools Daily bump. 2024-04-16 00:18:06 +00:00
include Daily bump. 2024-11-24 00:18:09 +00:00
INSTALL
libada Update copyright years. 2024-01-03 12:19:35 +01:00
libatomic Daily bump. 2024-11-19 00:19:52 +00:00
libbacktrace Daily bump. 2024-10-26 00:19:39 +00:00
libcc1 Daily bump. 2024-09-21 00:16:55 +00:00
libcody Update Copyright year in ChangeLog files 2024-01-03 11:35:18 +01:00
libcpp diagnostics: replace %<%s%> with %qs [PR104896] 2024-11-27 19:21:15 -05:00
libdecnumber Daily bump. 2024-04-03 00:17:29 +00:00
libffi Daily bump. 2024-10-26 00:19:39 +00:00
libgcc Daily bump. 2024-11-26 00:19:26 +00:00
libgfortran Daily bump. 2024-11-24 00:18:09 +00:00
libgm2 Daily bump. 2024-11-21 00:20:27 +00:00
libgo syscall: don't define syscall stub on Hurd 2024-10-30 11:33:07 -07:00
libgomp Fix 'libgomp.oacc-c/../libgomp.oacc-c-c++-common/acc_get_property-gcn.c' for C23 default 2024-11-28 15:17:36 +01:00
libgrust Daily bump. 2024-08-02 00:18:55 +00:00
libiberty Daily bump. 2024-11-20 00:19:59 +00:00
libitm Daily bump. 2024-11-19 00:19:52 +00:00
libobjc Daily bump. 2024-09-24 00:18:14 +00:00
libphobos Daily bump. 2024-11-19 00:19:52 +00:00
libquadmath Daily bump. 2024-08-29 00:19:25 +00:00
libsanitizer Daily bump. 2024-11-26 00:19:26 +00:00
libssp Daily bump. 2024-05-09 10:58:01 +00:00
libstdc++-v3 c++: Implement P2662R3, Pack Indexing [PR113798] 2024-11-28 10:16:46 -05:00
libvtv Daily bump. 2024-11-19 00:19:52 +00:00
lto-plugin Daily bump. 2024-08-24 00:18:13 +00:00
maintainer-scripts Daily bump. 2024-07-20 00:17:53 +00:00
zlib Daily bump. 2023-10-23 00:16:43 +00:00
.b4-config Add config file so b4 uses inbox.sourceware.org automatically 2024-07-28 11:13:16 +01:00
.dir-locals.el dir-locals: apply our C settings in C++ also 2024-07-31 20:38:27 +02:00
.gitattributes
.gitignore Git ignores .vscode 2024-09-12 22:51:00 +08:00
ABOUT-NLS
ar-lib
ChangeLog Daily bump. 2024-11-26 00:19:26 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in config-ml.in: Fix multi-os-dir search 2024-05-06 12:08:28 +08:00
config.guess
config.rpath
config.sub
configure nios2: Remove all support for Nios II target. 2024-11-25 18:07:35 +00:00
configure.ac nios2: Remove all support for Nios II target. 2024-11-25 18:07:35 +00:00
COPYING
COPYING.LIB
COPYING.RUNTIME
COPYING3
COPYING3.LIB
depcomp
install-sh
libtool-ldflags
libtool.m4 Build: fix error in fixinclude configure 2023-11-22 11:54:33 +01:00
ltgcc.m4
ltmain.sh ltmain.sh: allow more flags at link-time 2024-09-25 19:05:24 +01:00
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
MAINTAINERS nios2: Remove all support for Nios II target. 2024-11-25 18:07:35 +00:00
Makefile.def gccrs: Fix missing build dependency 2024-01-16 16:23:02 +01:00
Makefile.in Makefile.tpl: fix whitespace in licence header 2024-08-22 03:41:12 +01:00
Makefile.tpl Makefile.tpl: fix whitespace in licence header 2024-08-22 03:41:12 +01:00
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
SECURITY.txt Remove Debian from SECURITY.txt 2024-11-19 12:27:33 +01:00
symlink-tree
test-driver
ylwrap

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.