Например,
#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++), правильно?