https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70351
Bug ID: 70351
Summary: [C++11] static constexpr member cannot define with a
const qualifier
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: kariya_mitsuru at hotmail dot com
Target Milestone: ---
Please see the sample code below.
========================== sample code ==========================
struct T {};
struct S {
static constexpr T m{};
};
const T S::m;
int main(){}
========================== sample code ==========================
========================= error message =========================
prog.cc:7:12: error: 'constexpr' needed for in-class initialization of static
data member 'const T S::m' of non-integral type [-fpermissive]
const T S::m;
^
========================= error message =========================
cf. http://melpon.org/wandbox/permlink/TWKgHmFWnK07lCdm
I think that the code should be compiled successfully.
(The constexpr specifier has no effect on the type of a variable
except that it qualifies the variable as a const.)
Note that it is compiled successfully if T is an integral type.
========================== sample code ==========================
using T = int;
struct S {
static constexpr T m{};
};
const T S::m;
int main(){}
========================== sample code ==========================
cf. http://melpon.org/wandbox/permlink/59kDO82vFfFEsLJF
Note also that it is compiled successfully if a constexpr specifier
is used in the definition.
========================== sample code ==========================
struct T {};
struct S {
static constexpr T m{};
};
constexpr T S::m;
int main(){}
========================== sample code ==========================
cf. http://melpon.org/wandbox/permlink/pywyTowtvOVJ6sB5