Title
ODR violation with constant initialization possibly omitted
Status
drafting
Section
6.2 [basic.def.odr]
Submitter
Hubert Tong

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

Messages

Date: 2016-03-05.00:00:00

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
2016-03-05 00:00:00admincreate