gcc中的默认构造内联静态随机数引擎

时间:2018-05-13 09:33:41

标签: c++ gcc inline c++17 libstdc++

例如,

#include <random>

struct stru {
  //inline static std::mt19937 rnd; Oops!
  inline static std::mt19937 rnd{};  
};

int main() {

}

我发现两者没有语义差异,而clang在编译两者时没有问题。然而gcc 8.1会对第一个产生以下错误:

prog.cc:4:30: error: no matching function for call to 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::mersenne_twister_engine()'
   inline static std::mt19937 rnd;
                              ^~~
In file included from /opt/wandbox/gcc-8.1.0/include/c++/8.1.0/random:49,
                 from prog.cc:1:
/opt/wandbox/gcc-8.1.0/include/c++/8.1.0/bits/random.h:437:11: note: candidate: 'constexpr std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::mersenne_twister_engine(const std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>&)'
     class mersenne_twister_engine
           ^~~~~~~~~~~~~~~~~~~~~~~
/opt/wandbox/gcc-8.1.0/include/c++/8.1.0/bits/random.h:437:11: note:   candidate expects 1 argument, 0 provided
/opt/wandbox/gcc-8.1.0/include/c++/8.1.0/bits/random.h:437:11: note: candidate: 'constexpr std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::mersenne_twister_engine(std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>&&)'
/opt/wandbox/gcc-8.1.0/include/c++/8.1.0/bits/random.h:437:11: note:   candidate expects 1 argument, 0 provided

这是一个gcc错误(不是我的代码也不是libstdc ++),对吗?

0 个答案:

没有答案