For example,
#include <random>
struct stru {
//inline static std::mt19937 rnd; Oops!
inline static std::mt19937 rnd{};
};
int main() {
}
I see no semantic difference in the two, and clang has no problem in compiling both. Yet gcc 8.1 produces the following error for the first:
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
This is a gcc bug (not my code nor libstdc++), right?
This is a gcc bug (not my code nor libstdc++), right?
Right. It can be much more easily reproduced with this short snippet:
struct test {
explicit test() {};
};
struct stru {
inline static test t;
};
int main() {
test t;
}
The explicit
specifier is throwing GCC off. The same c'tor must be called both for initializing the static inline member and the local variable. And yet GCC initializes the local variable just fine, but complains about the inline static member.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With