Subject: Re: [boost] [config] unexpected explicit operators conversion on some compilers.
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2012-04-10 12:39:10
Le 31/03/12 08:49, Vicente J. Botet Escriba a écrit :
> Given the following explicit bool conversion
> template<typename Mutex>
> class unique_lock
> explicit operator bool() const BOOST_NOEXCEPT
> I was expecting the following code to compile fail (note the int cast)
> boost::unique_lock<boost::mutex> lk0;
> int i = int(lk0);
> It fails with gcc-4.7.0, but compile with gcc-4.6.2 and clang-3.0 (I
> have not tested yet with msvc).
> When BOOST_NO_EXPLICIT_CONVERSION_OPERATORS is defined I use the bool
> safe idiom to emulate the conversion
> #if defined(BOOST_NO_EXPLICIT_CONVERSION_OPERATORS)
> typedef void (unique_lock::*bool_type)();
> operator bool_type() const BOOST_NOEXCEPT;
> bool operator!() const BOOST_NOEXCEPT;
> explicit operator bool() const BOOST_NOEXCEPT;
> and in this case the compile fail as desired.
> Do we need a new macro to state that even if explicit operators are
> provide, there are some unexpected conversions that could be introduced?
has anyone some comments on this issue?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk