Complete (not)working example:
struct s { int i; };
template<const s* _arr>
class struct_array
{
public:
static constexpr auto arr = _arr[0]; // works
template<int >
struct inner // line 9, without this struct, it works
{
};
};
constexpr const s s_objs[] = {{ 42 }};
int main()
{
struct_array<s_objs> t_obj;
return 0;
}
Compiled like this:
g++ -std=c++11 -Wall constexpr.cpp -o constexpr
I get a running program with ideone's gcc 4.8.1, but 4.7.3 prints this to me:
constexpr.cpp: In instantiation of ‘class struct_array<((const s*)(& s_objs))>’:
constexpr.cpp:18:30: required from here
constexpr.cpp:9:16: error: lvalue required as unary ‘&’ operand
constexpr.cpp:9:16: error: could not convert template argument ‘(const s*)(& s_objs)’ to ‘const s*’
The last two lines are repeated 3 times. What's the reason, and is there any workaround to use my code on gcc 4.7.3?