[utility] addressof issue with classes having templated conversion operators

Hi folks, I've came across a problem with addressof() when the argument is of a class type with a template conversion operator. A minimal test case reproducing the issue is attached. Using boost 1.38, the example fails to compile under gcc 4.2.2, with the following error: ../../../../vendor/boost/boost_1_38_0/boost/utility/addressof.hpp: In function 'T* boost::addressof(T&) [with T = convertible]': addressof_conversion.cpp:17: instantiated from here boost/boost_1_38_0/boost/utility/addressof.hpp:42: error: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: ../../../../vendor/boost/boost_1_38_0/boost/utility/addressof.hpp:26: note: candidate 1: static T* boost::detail::addressof_impl<T>::f(T&, long int) [with T = convertible] ../../../../vendor/boost/boost_1_38_0/boost/utility/addressof.hpp:32: note: candidate 2: static T* boost::detail::addressof_impl<T>::f(T*, int) [with T = convertible] AFAICT gcc is right complaining here, according to 13.3.3 The same example compiles OK with boost 1.33.1, and the changeset that causes the difference seems to be this one: https://svn.boost.org/trac/boost/changeset/44705 Can this be considered a regression? How should this issue be addressed? Thanks, Gevorg

Gevorg Voskanyan:
Hi folks,
I've came across a problem with addressof() when the argument is of a class type with a template conversion operator. A minimal test case reproducing the issue is attached. Using boost 1.38, the example fails to compile under gcc 4.2.2, with the following error:
../../../../vendor/boost/boost_1_38_0/boost/utility/addressof.hpp: In function 'T* boost::addressof(T&) [with T = convertible]': addressof_conversion.cpp:17: instantiated from here boost/boost_1_38_0/boost/utility/addressof.hpp:42: error: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: ../../../../vendor/boost/boost_1_38_0/boost/utility/addressof.hpp:26: note: candidate 1: static T* boost::detail::addressof_impl<T>::f(T&, long int) [with T = convertible] ../../../../vendor/boost/boost_1_38_0/boost/utility/addressof.hpp:32: note: candidate 2: static T* boost::detail::addressof_impl<T>::f(T*, int) [with T = convertible]
AFAICT gcc is right complaining here, according to 13.3.3
The same example compiles OK with boost 1.33.1, and the changeset that causes the difference seems to be this one: https://svn.boost.org/trac/boost/changeset/44705
Can this be considered a regression?
Yes, this is a regression. Unfortunately, my attempts so far to fix it have been alternately thwarted by MSVC's ability to convert function pointers to void* and by the inclination of your convertible class to convert to anything. I'll keep trying.

Can this be considered a regression?
Yes, this is a regression.
See https://svn.boost.org/trac/boost/ticket/2878 and https://svn.boost.org/trac/boost/changeset/51872

Peter Dimov wrote:
See
https://svn.boost.org/trac/boost/ticket/2878
and
Thanks for the prompt response Peter! Glancing over the changes above it appears to be exactly the fix needed, but unfortunately I won't have access to gcc to test that until Monday. I'll let you know how it goes then. Again, thank you very much for this fix, Best Regards, Gevorg

Gevorg Voskanyan wrote:
Glancing over the changes above it appears to be exactly the fix needed, but unfortunately I won't have access to gcc to test that until Monday. I'll let you know how it goes then.
Hi Peter! I tested the fix in my environment and can confirm that it does solve the problem for me. Thanks! Best Regards, Gevorg
participants (2)
-
Gevorg Voskanyan
-
Peter Dimov