http://llvm.org/bugs/show_bug.cgi?id=15754

            Bug ID: 15754
           Summary: addressof returns wrong address when there is user
                    provided conversion operator to char&
           Product: libc++
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

addressof uses plain c style cast, so type conversion operator is invoked when
argument type T has user-defined conversion operator to char& like this:

struct nothing {
    operator char&()
    {
        static char c;
        return c;
    }
};

one way to fix this is using reinterpret_cast:
http://www.boost.org/doc/libs/release/boost/utility/addressof.hpp

template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_Tp*
addressof(_Tp& __x) _NOEXCEPT
{
    return reinterpret_cast<_Tp*>(&const_cast<char&>(reinterpret_cast<const
volatile char&>(__x)));
}

this code adding const volatile to char& and remove it for allowing addressof
to be called with const or volatile type _Tp.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to