You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CWG2531 [dcl.constexpr] Static data members redeclared as constexpr #1
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.hhstructX {
staticconstint x;
};
// TU 1
#include"x.hh"constexprint X::x{};
// TU 2
#include"x.hh"intmain() {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.)
changed the title [-][dcl.constexpr] Static data members redeclared as constexpr[/-][+]CWG2531 [dcl.constexpr] Static data members redeclared as constexpr[/+]on Feb 19, 2022
Activity
jensmaurer commentedon Feb 17, 2022
Reflector thread: http://lists.isocpp.org/core/2022/02/12017.php
jensmaurer commentedon Feb 18, 2022
@opensdh, please check: CWG2531
[-][dcl.constexpr] Static data members redeclared as constexpr[/-][+]CWG2531 [dcl.constexpr] Static data members redeclared as constexpr[/+]opensdh commentedon Feb 21, 2022
It looks correct; presumably you omitted the implementation behavior purposefully.
jensmaurer commentedon Feb 21, 2022
Yeah, I'm not sure it adds much, given that we want to outlaw the situation regardless.