CWG Issue 2494 (original) (raw)

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

2025-11-05


2494. Multiple definitions of non-odr-used entities

Section: 6.3 [basic.def.odr]Status: CD6Submitter: Hubert TongDate: 2021-07-02

[Accepted at the February, 2022 meeting.]

According to 6.3 [basic.def.odr] paragraph 10,

Every program shall contain exactly one definition of every non-inline function or variable that is odr-used in that program outside of a discarded statement (8.5.2 [stmt.if]); no diagnostic required.

This wording could be interpreted as allowing multiple definitions of non-inline variables and functions if they are not odr-used. That is presumably not the intent.

Notes from the August, 2021 teleconference:

CWG observed that there is a similar problem in paragraph 13. See also issue 1849.

Proposed resolution, December, 2021:

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

Each of the following is termed a definable item:

No translation unit shall contain more than one definition of any variable, function, class type, enumeration type, template, default argument for a parameter (for a function in a given scope), or default template argument definable item.

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

Every program shall contain exactly at least one definition of every non-inlinefunction or variable that is odr-used in that program outside of a discarded statement (8.5.2 [stmt.if]); no diagnostic required. The definition...

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

There can be more than one definition of a

in a program provided that each definition appears in a different translation unit and the definitions satisfy the following requirements. For any definable itemD with definitions in multiple translation units,

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 entity D defined in more than one translation unit item, for all definitions of D, or, if D is an unnamed enumeration, for all definitions of Dthat are reachable at any given program point, the following requirements shall be satisfied...

  1. Delete 6.3 [basic.def.odr] paragraph 15:

If these definitions do not satisfy these requirements, then the program is ill-formed; a diagnostic is required only if the entity is attached to a named module and a prior definition is reachable at the point where a later definition occurs.