Title
Unclear recursion in the one-definition rule
Status
open
Section
6.3 [basic.def.odr]
Submitter
Johannes Schaub

Created on 2023-08-19.00:00:00 last changed 15 months ago

Messages

Date: 2023-08-19.06:44:31

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.
Date: 2023-09-17.10:38:31

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

History
Date User Action Args
2023-08-19 06:44:31adminsetmessages: + msg7395
2023-08-19 00:00:00admincreate