mercredi 29 mars 2017

Why does `std::make_shared` perform two separate allocations with `-fno-rtti`?

#include <memory>
struct foo { };
int main() { std::make_shared<foo>(); }

The asssembly generated by g++7 -fno-exceptions -Ofast for the code above:

  • Contains a single call to operator new if -fno-rtti is not passed.

  • Contains two separate calls to operator new if -fno-rtti is passed.

This can be easily verified on gcc.godbolt.org:

screenshot of the above godbolt link with highlighed operator new calls

Why is this happening? Why does disabling RTTI prevent make_shared from unifying the object and control block allocations?

Aucun commentaire:

Enregistrer un commentaire