Title
Multiple definitions of non-odr-used entities
Status
cd6
Section
6.3 [basic.def.odr]
Submitter
Hubert Tong

Created on 2021-07-02.00:00:00 last changed 28 months ago

Messages

Date: 2022-09-25.18:08:42

Proposed resolution, December, 2021:

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

  2. Each of the following is termed a definable item:

    • a class type ( Clause 11 [class]),

    • an enumeration type (9.7.1 [dcl.enum]),

    • a function (9.3.4.6 [dcl.fct]),

    • a variable (6.1 [basic.pre]),

    • a templated entity (13.1 [temp.pre]),

    • a default argument for a parameter (for a function in a given scope) (9.3.4.7 [dcl.fct.default]), or

    • a default template argument (13.2 [temp.param]).

    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.

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

  4. Every program shall contain exactly at least 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. The definition...
  5. Change 6.3 [basic.def.odr] paragraph 13 as follows:

  6. There can be more than one definition of a

    • class type (Clause 11 [class]),

    • enumeration type (9.7.1 [dcl.enum]),

    • inline function or variable (9.2.8 [dcl.inline]),

    • templated entity (13.1 [temp.pre]),

    • default argument for a parameter (for a function in a given scope) (9.3.4.7 [dcl.fct.default]), or

    • default template argument (13.2 [temp.param])

    in a program provided that each definition appears in a different translation unit and the definitions satisfy the following requirements. 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 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 D that are reachable at any given program point, the following requirements shall be satisfied...

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

  8. 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.
Date: 2021-08-15.00:00:00

Notes from the August, 2021 teleconference:

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

Date: 2022-02-15.00:00:00

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

History
Date User Action Args
2022-08-19 07:54:33adminsetstatus: dr -> cd6
2022-02-15 00:00:00adminsetstatus: ready -> dr
2022-01-06 00:00:00adminsetmessages: + msg6595
2022-01-06 00:00:00adminsetstatus: drafting -> ready
2021-11-15 00:00:00adminsetmessages: + msg6535
2021-07-02 00:00:00admincreate