field initializer is not constant g++ 4.8.4

2019-07-30 09:37发布

I tried to compile the following code on my laptop, using g++ 4.8.4:

#include <algorithm>
#include <iostream>
#include <initializer_list>
#include <tuple>

struct Storage {
  static const int num_spatial_subset = 8;
  static constexpr std::initializer_list<std::initializer_list<double>> vectors{ {0,0,0}, 
      {0,1,0}, 
      {0,0,1}, 
      {1,1,0}, 
      {1,0,1}, 
      {0,1,1}, 
      {1,0,0}, 
      {1,1,1} };
  double storage[num_spatial_subset][vectors.size()];
};


int main()
{
}

And I got this error message:

error: field initializer is not constant
constexpr std::initializer_list< std::initializer_list<double> > vectors{ {0,0,0}, {0,1,0}, {0,0,1}, {1,1,0}, {1,0,1}, {0,1,1}, {1,0,0}, {1,1,1} };

However, I copy/paste the same code on coliru (g++ 6.1.0), with the same compilation parameters and it worked.

Can someone tells me what is wrong please ?

Thank you.

1条回答
【Aperson】
2楼-- · 2019-07-30 10:20

Actually, as pointed out by Chris and Baum, updating to g++ 4.9 fixed it.

查看更多
登录 后发表回答