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

c++: Fix ICE with -Wsubobject-linkage and function types.

Fixes an Internal Compiler Error (ICE) when using the -Wsubobject-linkage warning with function types.

This commit addresses an Internal Compiler Error (ICE) that occurred when the -Wsubobject-linkage warning was enabled for code involving function types or pointers to data members. The compiler crashed when attempting to access TYPE_MAIN_DECL of a function type, which lacks such a declaration. The fix adds a check for OVERLOAD_TYPE_P before calling decl_anon_ns_mem_p, preventing the invalid access.

In Details

Fixes an ICE in decl_namespace_context when processing a type with TYPE_MAIN_DECL being null, which occurs for function types or pointer-to-data-member types. This was triggered by constrain_class_visibility when emitting -Wsubobject-linkage for constructs like struct S { void (*f) (P *); };. The fix inserts a check for OVERLOAD_TYPE_P before calling decl_anon_ns_mem_p.

For Context
ICE
Internal Compiler Error. An unexpected condition encountered by the compiler during translation that prevents it from continuing compilation.
-Wsubobject-linkage
A GCC warning option that diagnostics linkage issues related to subobjects, particularly within classes and namespaces.
function type
In C++, a type that describes a function, including its return type and the types of its parameters. For example, void() is a function type.
TYPE_MAIN_DECL
An internal GCC internal data structure field that points to the primary declaration associated with a type.
OVERLOAD_TYPE_P
A GCC macro that checks if a given type is an overloaded type, typically associated with function overloads or template specializations.
Filed Under: c++compilerbugfixwarning