c++: Handle anonymous namespaces in module partitions correctly
Fixes an ICE in C++ module partitions by correctly handling anonymous namespaces local to a translation unit.
This commit resolves an ICE (Internal Compiler Error) related to C++ module partitions and anonymous namespaces. Previously, the compiler incorrectly included anonymous namespaces from other partitions, leading to duplicate definitions and compilation failures. The fix prevents anonymous namespaces, which are local to a translation unit, from being forced out into module partitions, thereby resolving conflicts and enabling correct compilation.
In Details
Modifies depset::hash::add_namespace_entities in gcc/cp/module.cc to prevent anonymous namespaces from being forced out when processing module partitions. This corrects an ICE caused by treating TU-local anonymous namespaces as if they belonged to other partitions, resolving PR c++/126209.
- anonymous namespace
- A C++ construct that allows declarations to have internal linkage, making them visible only within the current translation unit (source file). It is semantically similar to a named namespace with a unique, compiler-generated name.
- module partition
- In C++20 modules, a way to organize declarations within a module. Each partition can have its own set of visible entities, and they are combined to form the complete module.
- translation unit
- A single source file after it has been preprocessed. It's the input to the compiler's main parsing and analysis phases.
- ICE
- Internal Compiler Error. A severe error within the compiler's own logic that prevents it from completing compilation, usually resulting in a crash.