This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/66656] New: static constexpr array member: cannot get size via constexpr function
- From: "g5834847 at trbvm dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 24 Jun 2015 19:02:09 +0000
- Subject: [Bug c++/66656] New: static constexpr array member: cannot get size via constexpr function
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66656
Bug ID: 66656
Summary: static constexpr array member: cannot get size via
constexpr function
Product: gcc
Version: 4.9.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: g5834847 at trbvm dot com
Target Milestone: ---
////////////////////////////////////////
#include <iostream>
template <typename T, size_t N>
constexpr size_t array_size(const T (&)[N])
{
return N;
}
class X {
public:
struct item {
char const* const name;
int price;
};
static const item arr0[2];
static constexpr item arr1[3] = {{"asdf", 0}, {"qwer", 1}, {"zxcv", 2}};
static size_t constexpr size0() {
return array_size(arr0); // perfect
}
static size_t constexpr size1() {
return array_size(arr1); // problem!!
}
};
const X::item X::arr0[] = {{"asdf", 0}, {"qwer", 1}};
int main()
{
X x;
std::cout << x.size0() << std::endl; // perfect
std::cout << x.size1() << std::endl; // ERROR IN THIS LINE (cannot link!??)
return 0;
}
////////////////////////////////////////////
$ c++ -std=c++14 -o go go.cpp
/tmp/ccPGS4ZN.o: In function `X::size1()':
go.cpp:(.text._ZN1X5size1Ev[_ZN1X5size1Ev]+0x5): undefined reference to
`X::arr1'
collect2: error: ld returned 1 exit status