Nathaniel Shead 7921bb4afc c++: Implement P2115R0 linkage changes for unnamed unscoped enums [PR120503]
We currently list P2115R0 as implemented, but only the modules changes
had been done.  This patch implements the linkage changes so that
unnamed unscoped enums will use the name of the first enumerator for
linkage purposes.

This is (strictly speaking) a breaking change, as code that previously
relied on unnamed enumerations being internal linkage may have overloads
using those types become exposed and clash with other functions in a
different TU that have been similarly exposed.  As such this feature is
only implemented for C++20.

No ABI flag warning is provided, partly because C++20 is still an
experimental standard, but also because any affected functions could not
have been part of an ABI until this change anyway.

A number of testcases that are testing for behaviour of no-linkage types
are adjusted to use an enumeration with no values, so that the pre-C++20
and post-C++20 behaviour is equivalently tested.

In terms of implementation, I had originally considered adjusting the
DECL_NAME of the enum, as with 'name_unnamed_type', but this ended up
being more complicated as it had unwanted interactions with the existing
modules streaming and with name lookup and diagnostic messages.  This
patch instead uses a new function to derive this case.

The standard says that ([dcl.enum] p11) such an enum "...is denoted, for
linkage purposes, by its underlying type and its first enumerator", so
we need to add a new mangling production as well to handle this.

	PR c++/120503
	PR c++/120824

gcc/cp/ChangeLog:

	* cp-tree.h (TYPE_UNNAMED_P): Adjust for enums with enumerators
	for linkage purposes.
	(enum_with_enumerator_for_linkage_p): Declare.
	* decl.cc (name_unnamed_type): Adjust assertions to handle enums
	with enumerators for linkage purposes.
	(grokdeclarator): Use a typedef name for enums with enumerators
	for linkage purposes.
	(enum_with_enumerator_for_linkage_p): New function.
	(finish_enum_value_list): Reset type linkage for enums with
	enumerators for linkage purposes.
	* mangle.cc (write_unnamed_enum_name): New function.
	(write_unqualified_name): Handle enums with enumerators for
	linkage purposes.
	* tree.cc (decl_linkage): Fixup unnamed enums.

gcc/testsuite/ChangeLog:

	* g++.dg/abi/mangle32.C: Remove enumerator list.
	* g++.dg/cpp0x/linkage2.C: Likewise.
	* g++.dg/ext/vector26.C: Likewise.
	* g++.dg/other/anon3.C: Likewise.
	* g++.dg/abi/mangle83.C: New test.
	* g++.dg/modules/enum-15_a.C: New test.
	* g++.dg/modules/enum-15_b.C: New test.

include/ChangeLog:

	* demangle.h (enum demangle_component_type): Add enumeration
	DEMANGLE_COMPONENT_UNNAMED_ENUM.

libiberty/ChangeLog:

	* cp-demangle.c (d_unnamed_enum): New function.
	(d_unqualified_name): Call it.
	(cplus_demangle_type): Handle unscoped unnamed types
	(Ue, Ul, etc.)
	(d_count_templates_scopes): Handle unnamed enums.
	(d_find_pack): Likewise.
	(d_print_comp_inner): Print unnamed enums.
	* testsuite/demangle-expected: Add tests.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
2025-08-17 10:14:14 +10:00
2025-06-03 00:18:06 +00:00
2025-08-11 00:16:52 +00:00
2025-08-08 00:18:50 +00:00
2025-08-16 00:19:12 +00:00
2025-06-23 00:16:33 +00:00
2025-01-02 11:59:57 +01:00
2025-08-01 00:20:20 +00:00
2025-04-11 00:17:32 +00:00
2025-07-26 00:19:51 +00:00
2025-08-16 00:19:12 +00:00
2025-01-02 11:59:57 +01:00
2024-10-26 00:19:39 +00:00
2025-08-14 00:20:55 +00:00
2025-08-14 00:20:55 +00:00
2025-08-07 00:20:46 +00:00
2025-07-24 00:20:56 +00:00
2025-08-07 00:20:46 +00:00
2025-08-06 00:21:26 +00:00
2025-05-10 00:17:59 +00:00
2025-01-02 11:59:57 +01:00
2025-07-02 00:19:39 +00:00
2025-04-10 00:18:06 +00:00
2025-01-02 11:59:57 +01:00
2025-08-11 00:16:52 +00:00
2025-05-10 00:17:59 +00:00
2025-03-07 00:17:19 +00:00
2025-07-05 00:19:48 +00:00
2025-08-01 00:20:20 +00:00
2025-08-15 00:17:03 +00:00
2024-11-19 12:27:33 +01:00

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.
Description
No description provided
Readme 1.5 GiB
Languages
C++ 30.7%
C 30%
Ada 14.5%
D 6.1%
Go 5.7%
Other 12.5%