boostorg / container

STL-like containers from Boost
http://www.boost.org/libs/container/
Boost Software License 1.0
103 stars 113 forks source link

Vector with custom allocator does not support value types with operator& #81

Closed gix closed 5 years ago

gix commented 6 years ago

Commit 42c6be5887b34b67be4d54041acab12157d080f9 broke use of vector with custom allocator and types that define operator&.

Repro on godbolt:

#include <boost/container/vector.hpp>

struct X;

template<typename T>
struct XRef
{
    explicit XRef(T* ptr) noexcept : ptr(ptr) {}
    operator T*() const noexcept { return ptr; }
    T* ptr;
};

struct X
{
    XRef<X const> operator&() const noexcept { return XRef<X const>(this); }
    XRef<X>       operator&()       noexcept { return XRef<X>(this); }
};

int main()
{
    boost::container::vector<X> x(5);
    return 0;
}

It comes down to construct and destroy calls using &v instead of addressof(v).

igaztanaga commented 5 years ago

The following commit fixed the issue some weeks ago:

https://github.com/boostorg/container/commit/f28fe5d33ef3f4ce6959fb1958dfaa336b04d204

Many thanks for the report.

gix commented 5 years ago

This is still not fully fixed. See repro using latest boost 1.70: https://godbolt.org/z/WYJoPv