GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
c++

Fix mangling for empty unnamed anonymous unions/structs.

Correctly mangles empty anonymous unions or structs as unnamed data members.

This commit fixes an internal compiler error (ICE) that occurred when mangling empty anonymous unions or structs used as non-static data members. Previously, the mangling process failed because it expected a name for these constructs. The fix introduces a new mangling scheme, using an index instead of a name, similar to how unnamed bitfields are handled. This ensures correct name mangling for these C++ constructs, resolving bug PR125541.

In Details

The C++ name mangler (mangle.cc) incorrectly handled empty anonymous aggregate data members, leading to an ICE. This commit modifies write_reflection to use a different mangling prefix ('da' instead of 'dm') and an index for such members, akin to unnamed bitfields. This resolves PR125541 by providing a stable mangling for these edge cases without relying on a non-existent name, preserving ABI compatibility for reflection metadata.

For Context
ICE
Internal Compiler Error. This indicates a bug within the compiler itself, where it encounters an unexpected state and cannot continue compilation.
mangling
The process of encoding C++ type and declaration information into a unique string, typically used by linkers to distinguish between functions and variables with the same name but different types or scopes. This is also known as name decoration.
anonymous union/struct
An unnamed union or struct that is defined directly within another class or struct, allowing its members to be accessed as if they were members of the outer class. In C++, these are also known as unnamed nested-scope data members (NSDMs).
non-static data members (NSDMs)
Member variables of a class or struct that are not declared with the static keyword. Each object of the class has its own copy of non-static data members.
reflection
A feature that allows a program to inspect and manipulate its own structure, properties, and metadata at runtime. In C++, this can involve querying type information, member names, and other details.
Filed Under: c++compilerbugfixmangling