[Boost-bugs] [Boost C++ Libraries] #9497: mpq_rational asserts when used in variant

Subject: [Boost-bugs] [Boost C++ Libraries] #9497: mpq_rational asserts when used in variant
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-12-16 01:14:02

#9497: mpq_rational asserts when used in variant
 Reporter: András Kucsma <r0maikx02b@…> | Owner: johnmaddock
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: multiprecision
  Version: Boost 1.55.0 | Severity: Problem
 Keywords: |
 The following code fails with an assertion:
 #include <boost/variant.hpp>
 #include <boost/multiprecision/gmp.hpp>

 struct Foo {
         Foo() {}
         Foo(const Foo&) {}

 int main() {
         typedef boost::multiprecision::mpq_rational Num;
         typedef boost::variant<Foo, Num> Variant;

         Variant x = Num(2);
         Variant y = std::move(x);

         x = Foo();
 Assert text:
 test: /usr/local/include/boost/multiprecision/gmp.hpp:1947: __mpq_struct
 (& boost::multiprecision::backends::gmp_rational::data())[1]: Assertion
 `m_data[0]._mp_num._mp_d' failed.

 Some notes on the code:
 * The explicit copy constructor for Foo is necessary
 * Replacing mpq_rational with mpz_int or cpp_rational doesn't cause
 * Using boost::move without the -std=c++11 flag doesn't assert. (but it
 does assert with -std=c++11)

 Tested on Linux with:
 * g++-4.8.1, g++-4.8.2, clang 3.5 (trunk 197340)
 * boost-1.55.0 and trunk revision: 86799
 * libgmp 5.1.0

 Compiled with the command:
 (clan)g++ -std=c++11 main.cpp /usr/local/lib/libgmp.a -O0 -g

 The source of the problem could very well be in how variant handles move
 semantics in C++11 mode.

 Note: you can also find this file here:

Ticket URL: <https://svn.boost.org/trac/boost/ticket/9497>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC