Title
ODR violation with constant initialization possibly omitted
Status
c++23
Section
6.3 [basic.def.odr]
Submitter
Hubert Tong

Created on 2016-03-05.00:00:00 last changed 16 months ago

Messages

Date: 2022-11-12.03:34:57

Proposed resolution (approved by CWG 2022-11-11):

Insert after 6.3 [basic.def.odr] bullet 14.7 as follows:

  • ...
  • In each such definition, corresponding entities shall have the same language linkage.
  • In each such definition, const objects with static or thread storage duration shall be constant-initialized if the object is constant-initialized in any such definition.
  • ...
Date: 2022-11-27.21:00:25
P2720R0 comment USĀ 5-033

[Accepted as a DR at the November, 2022 meeting.]

Consider the following example:

  // tu1.cpp
  extern const int a = 1;
  inline auto f() {
    static const int b = a;
    struct A { auto operator()() { return &b; } } a;
    return a;
  }

  // tu2.cpp
  extern const int a;
  inline auto f() {
    static const int b = a;
    struct A { auto operator()() { return &b; } } a;
    return a;
  }
  int main() {
    return *decltype(f())()();
  }

Here, b may or may not have constant initialization. This example should be an ODR violation.

(Split off from issue 2123.)

History
Date User Action Args
2023-07-16 13:00:43adminsetstatus: open -> c++23
2023-07-16 13:00:43adminsetstatus: drwp -> open
2023-02-18 18:43:04adminsetstatus: dr -> drwp
2022-11-25 05:14:04adminsetstatus: nb -> dr
2022-11-12 03:34:57adminsetmessages: + msg7002
2022-11-12 03:34:57adminsetstatus: drafting -> nb
2016-03-05 00:00:00admincreate