GMP and C++11 move constructors

Hans Åberg haberg-1 at telia.com
Fri May 18 13:17:09 UTC 2018


> On 18 May 2018, at 15:01, Marc Glisse <marc.glisse at inria.fr> wrote:
> 
> On Fri, 18 May 2018, Hans Åberg wrote:
> 
>> FYI, if one follows the GMP API, it forces C++11 move constructors to make a heap allocation via mpz_init, which then is immediately destroyed using mpz_clear. The reason is that the API does not guarantee that nothing happens if the pointer is set to NULL even if one uses a deallocator, like 'free', with that property.
> 
> If you look at the current repository, you'll notice that mpz_init does not perform a heap allocation anymore.

But it looks like it isn't NULL, so I gather mpz_clear checks for that value, otherwise it will crash on 'free'.




More information about the gmp-discuss mailing list