Title
Treatment of closure types in the one-definition rule
Status
open
Section
6.3 [basic.def.odr]
Submitter
Brian Bi

Created on 2023-07-20.00:00:00 last changed 11 months ago

Messages

Date: 2023-09-17.10:38:31

Consider:

  inline auto lambda = []{}; // same in different translation units or not?

This can be observed, for example, through the following variable template:

  template<class T> int v;

Is &v<decltype(lambda)> the same address in every translation unit?

Possible resolution:

  1. Change in 6.3 [basic.def.odr] paragraph 14 as follows:

    For any definable item D with definitions in multiple translation units,
    • if D is a non-inline non-templated function or variable, or
    • if the definitions in different translation units do not satisfy the following requirements,
    the program is ill-formed; a diagnostic is required only if the definable item is attached to a named module and a prior definition is reachable at the point where a later definition occurs. Given such an item, for all definitions of D, or, if D is an unnamed enumeration, for all definitions of D that are reachable at any given program point, the following requirements shall be satisfied, where the definition of a closure type is considered to consist of the sequence of tokens of the corresponding lambda-expression.
    • ...
    • Each such definition shall consist of the same sequence of tokens, where the definition of a closure type is considered to consist of the sequence of tokens of the corresponding lambda-expression.
    • ...
  2. Add another example after example 6, immediately before 6.3 [basic.def.odr] paragraph 18:

    [ Example:
      inline decltype([]{}) v1;
      inline auto v2 = []{};
    
    If the definition of v1 appears in multiple translation units, the program is ill-formed, no diagnostic required, because each definition declares v1 to have a different type. If the definition of v2 appears in multiple translation units, the behavior of the program is as if there is only one definition, and only a definition can supply an initializer; therefore the behavior is as if there is only one initializer. Therefore, v2 has the same type in every translation unit. -- end example]

    If, at any point in the program, there is more than one reachable unnamed enumeration definition in the same scope...

History
Date User Action Args
2023-07-20 00:00:00admincreate