Multiple definitions of enumerators
tentatively ready
6.3 [basic.def.odr]
Naiver Miigon

Created on 2021-02-10.00:00:00 last changed 4 days ago


Date: 2022-12-02.23:19:47

Proposed resolution (approved by CWG 2022-12-02):

Change in 9.7.1 [dcl.enum] paragraph 2 as follows:

... The identifiers in an enumerator-list are declared as constants, and can appear wherever constants are required. The same identifier shall not appear as the name of multiple enumerators in an enumerator-list. An enumerator-definition with = gives the associated enumerator the value indicated by the constant-expression. If the first enumerator has no initializer, the value of the corresponding constant is zero. An enumerator-definition without an initializer gives the enumerator the value obtained by increasing the value of the previous enumerator by one.
Date: 2022-12-02.23:19:47

Suggested resolution [SUPERSEDED]:

Change 6.3 [basic.def.odr] paragraph 1 as follows:
Each of the following is termed a definable item:
  • ...
  • an enumeration type (9.7.1 [dcl.enum]),
  • an enumerator,
  • a function ( [dcl.fct]),
  • ...
Date: 2021-02-10.00:00:00

Issue 2494 specified a list of definable items and required that no translation unit contain more than one definition of any of those items. However, the list omits enumeration constants, implicitly allowing an example like:

  enum E { e, e };

According to 6.1 [basic.pre] paragraph 3, an enumerator is an entity. According to 6.2 [basic.def] paragraph 2,

Each entity declared by a declaration is also defined by that declaration unless: ...

and enumerators are not on the list of excluded cases, so an enumerator-definition is a definition. Furthermore, 6.6 [basic.link] paragraph 8 says,

Two declarations of entities declare the same entity if, considering declarations of unnamed types to introduce their names for linkage purposes, if any (9.2.4 [dcl.typedef], 9.7.1 [dcl.enum]), they correspond (6.4.1 [basic.scope.scope]), have the same target scope that is not a function or template parameter scope, and either

  • they appear in the same translation unit, or

  • ...

In the example above, both enumerators thus define the same entity, so the one-definition rule is responsible for excluding the duplicate definitions but does not do so.

Date User Action Args
2022-12-02 23:19:47adminsetmessages: + msg7073
2022-12-02 23:17:30adminsetstatus: drafting -> tentatively ready
2022-11-20 07:54:16adminsetstatus: open -> drafting
2022-02-18 07:47:23adminsetmessages: + msg6729
2021-02-10 00:00:00admincreate