This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-11-11
(From submission #402.)
Consider the following tokens appearing in multiple translation units:
inline void f() { int a; int b = a; }
Does f violate the one-definition rule?
We have this check in 6.3 [basic.def.odr] paragraph 14.5:
- ...
- In each such definition, corresponding names, looked up according to 6.5 [basic.lookup], shall refer to the same entity, ...
- ...
Does a refer to the same entity in the several definitions of f? Subclause 6.3 [basic.def.odr] paragraph 16 specifies:
These requirements also apply to corresponding entities defined within each definition of D (including the closure types of lambda-expressions, but excluding entities defined within default arguments or default template arguments of either D or an entity not defined within D). For each such entity and for D itself, the behavior is as if there is a single entity with a single definition, including in the application of these requirements to other entities.
Thus, the requirements apply recursively to the definitions of a, but it is unclear whether the conclusion "as if there is a single entity with a single definition" is reached at each level of the recursion separately.
Suggested resolution:
Change in 6.3 [basic.def.odr] paragraph 16 as follows:
If these requirements are satisfied, the behavior for D is as if there is a single entity with a single definition, including in the application of these requirements to other entities.These requirementsThis behavior alsoapplyapplies to corresponding entities defined within each definition of D (including the closure types of lambda-expressions, but excluding entities defined within default arguments or default template arguments of either D or an entity not defined within D).For each such entity and for D itself, the behavior is as if there is a single entity with a single definition, including in the application of these requirements to other entities.