This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-12-19


2781. Unclear recursion in the one-definition rule

Section: 6.3  [basic.def.odr]     Status: open     Submitter: Johannes Schaub     Date: 2023-08-19

(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:

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 requirements This behavior also apply applies 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.