完全な (ない) 動作例:
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;
}
次のようにコンパイルされます。
g++ -std=c++11 -Wall constexpr.cpp -o constexpr
ideone の gcc 4.8.1 で実行中のプログラムを取得しますが、4.7.3 では次のように出力されます。
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*’
最後の 2 行は 3 回繰り返されます。理由は何ですか? gcc 4.7.3 で私のコードを使用するための回避策はありますか?