However, omitting the NDEBUG flag will trigger an assertion failure:
main: /usr/include/boost/multiprecision/gmp.hpp:1296: const mpz_t &boost::multiprecision::backends::gmp_int::data() const: Assertion `m_data[0]._mp_d' failed. Aborted (core dumped) That indicates that an uninitialized variable was used.
Compiling the same program with g++4.9.2 (with or without "-DNDEBUG") yields the expected result:
6 6
What did I miss? Can this behavior indeed be traced down to Boost.Multiprecision, or does it have to do with the initialization order of static const class members? Or something else?
I would say initialization order.
Additionally, both variants work correctly with clang when using a built-in type like 'int'.
For type int, the values are computed recursively at compile time, for a user-defined-type the values are computed at runtime and you hit initialization-order issues. HTH, John.