Boost logo

Boost :

Subject: [boost] [container] ::flat_map function force_copy break strict-aliasing on gcc < 4.4
From: Владислав Щапов (phprus_at_[hidden])
Date: 2017-01-31 02:20:39


Hello!

On function:

template<class D, class S>
BOOST_CONTAINER_FORCEINLINE static D force_copy(S s)
{
   D *vp = reinterpret_cast<D *>(&s);
   return D(*vp);
}

gcc 4.3.4 (SLE 11) produced wrong code.
It seems that the compiler does not create a copy of an object "s" and
returns an object of D().

If I change the signature of function on "BOOST_CONTAINER_FORCEINLINE
static D force_copy(const S& s)" the code works and the tests pass. But
then does not create a copy of an object "s" in a function call.

I'm not sure that this change is correct.
Is there any other workaround for this problem with a compiler gcc 4.3 or
better disable strict-aliasing?

--
Best regards,
Vladislav

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk