-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Reference (section label)
[dcl.constexpr]/1
Issue description
C++17 made constexpr static data members implicitly inline:
A function or static data member declared with the constexpr or consteval specifier is implicitly an inline function or variable ([dcl.inline]).
However, that makes the following well-formed C++14 program IFNDR per [dcl.inline]/5:
// 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;}
Current GCC and Clang do treat X::x
as a weak symbol, but since they emit it even without an odr-use in the TU programs like this do work in practice.
Suggested resolution
Change [dcl.constexpr]/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 ([dcl.inline]). […]
(Functions must be declared constexpr
on every declaration if on any, so this isn't a change for them.)