Boost logo

Boost Users :

Subject: Re: [Boost-users] [Multiprecision] Runtime assertion failure with clang++3.6.0 but not g++4.9.2
From: John Maddock (jz.maddock_at_[hidden])
Date: 2016-02-08 14:14:19


> 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.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net