forwprop: Wrap C++ enums/structs in anonymous namespace
Prevents ODR violations by localizing C++ types in the forward propagation pass.
This commit encapsulates the long_mul_kind enum, long_mul_extract enum, and long_mul_summand struct within an anonymous namespace in tree-ssa-forwprop.cc. This change prevents potential One Definition Rule (ODR) conflicts by ensuring these types are local to the translation unit, rather than polluting the global scope. This improves code modularity and avoids issues in larger projects where symbol name collisions could occur.
In Details
In C++, entities declared at namespace scope (including global scope) must have unique names across all translation units that use them if they are to be used in a way that might lead to linkage. This commit wraps long_mul_kind, long_mul_extract, and long_mul_summand in an anonymous namespace within tree-ssa-forwprop.cc. This makes them internal to that specific .cc file, preventing potential ODR violations if similar type names were used elsewhere in GCC, even if they represent different concepts.
- anonymous namespace
- A C++ construct that allows declarations to have internal linkage, meaning they are only visible within the current translation unit (source file). This is an alternative to using
staticfor internal linkage. - ODR conflict
- A violation of the One Definition Rule (ODR) in C++, which states that any non-inline function or variable must have exactly one definition in the program. Conflicts arise when a name is defined multiple times in a way that violates this rule, often due to linkage issues.
- translation unit
- A source file after it has been processed by the C++ preprocessor. It's the unit that the compiler compiles.