C++ modules relax redefinition restrictions for imported entities
C++ modules now allow redefinition of imported global entities, simplifying well-formed code compilation.
This commit implements a relaxation of redefinition restrictions for imported global module entities in C++, aligning with the P1811 proposal. The compiler now skips redundant definitions of imported entities, improving compilation speed for well-formed code. While this prioritizes speed over strict ODR checking for certain ill-formed cases, it correctly handles valid redefinitions. The change affects how entities are looked up and checked after import.
In Details
This patch implements P1811's allowance for redefining imported global module entities by skipping the tokens of redundant definitions. This behavior is controlled by redefinable_import_p. The implementation defers ODR checking for redefinitions until check_module_override and handles class redefinitions after lookup and push. The commit acknowledges a limitation in allowing multiple redefinitions after an import (e.g., p1811-5) but defers fixing it for simplicity, assuming definitions satisfy ODR when originating from the same source. The flag -fno-module-include-translate is also intr…
- C++ Modules
- A feature in C++ designed to improve build times and code organization by providing a more robust and efficient alternative to header files. Modules allow for explicit export and import of declarations.
- P1811
- A C++ proposal (likely referring to the standard's evolution) that addresses specific aspects of module handling, particularly regarding redefinition restrictions and imported entities.
- global module entity
- In the context of C++ Modules, a declaration (like a class, function, or variable) that is defined at the global scope and made available through a module.
- redefinition
- Defining an entity (like a variable, function, or class) more than once in a program. This can lead to linker errors or undefined behavior, although C++ Modules introduce specific rules for imported entities.
- ODR
- One Definition Rule. A C++ rule stating that non-inline functions and variables must have exactly one definition in the program.
- -fno-module-include-translate
- A compiler flag that likely disables a specific translation or processing step related to how C++ module includes are handled. Its exact effect is to force textual inclusion, bypassing module processing.
- translation unit
- A single source code file, after preprocessing, that is compiled by the compiler. It typically corresponds to one
.ccor.cppfile.