Title
Static data members redeclared as constexpr
Status
drwp
Section
9.2.6 [dcl.constexpr]
Submitter
Davis Herring

Created on 2022-02-16.00:00:00 last changed 7 months ago

Messages

Date: 2023-11-08.05:03:56

Proposed resolution (reviewed by CWG 2023-02-07, approved by CWG 2023-11-07):

Change 9.2.6 [dcl.constexpr] paragraph 1 as follows:

A function or static data member declared with the constexpr or consteval specifier on its first declaration is implicitly an inline function or variable (9.2.8 [dcl.inline]).

Drafting note: Functions must be declared constexpr on every declaration if on any, so this isn't a change for them.

Date: 2023-11-15.00:00:00

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

C++17 made constexpr static data members implicitly inline (9.2.6 [dcl.constexpr] paragraph 1):

A function or static data member declared with the constexpr or consteval specifier is implicitly an inline function or variable (9.2.8 [dcl.inline]).

However, that makes the following well-formed C++14 program ill-formed, no diagnostic required, per 9.2.8 [dcl.inline] paragraph 5:

If a function or variable with external or module linkage is declared inline in one definition domain, an inline declaration of it shall be reachable from the end of every definition domain in which it is declared; no diagnostic is required.
  // x.hh
  struct X {
    static const int x;
  };

  // TU 1
  #include "x.hh"
  constexpr int X::x{};

  // TU 2
  #include "x.hh"
  int main() { return !&X::x; }
History
Date User Action Args
2024-04-05 21:43:46adminsetstatus: dr -> drwp
2023-12-19 10:15:28adminsetstatus: ready -> dr
2023-11-08 05:03:56adminsetstatus: review -> ready
2023-02-10 23:01:52adminsetstatus: tentatively ready -> review
2023-02-08 03:23:14adminsetstatus: open -> tentatively ready
2022-02-18 07:47:23adminsetmessages: + msg6731
2022-02-16 00:00:00admincreate