[config] unexpected explicit operators conversion on some compilers.

Hi, Given the following explicit bool conversion template<typename Mutex> class unique_lock { public: 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; #else explicit operator bool() const BOOST_NOEXCEPT; #endif 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? Best, Vicente

Le 31/03/12 08:49, Vicente J. Botet Escriba a écrit :
Hi,
Given the following explicit bool conversion
template<typename Mutex> class unique_lock { public: 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; #else explicit operator bool() const BOOST_NOEXCEPT; #endif
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?
Hi, has anyone some comments on this issue? Best, Vicente
participants (1)
-
Vicente J. Botet Escriba