[LLVMbugs] [Bug 15754] New: addressof returns wrong address when there is user provided conversion operator to char&
    bugzilla-daemon at llvm.org 
    bugzilla-daemon at llvm.org
       
    Mon Apr 15 17:52:14 PDT 2013
    
    
  
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: hhinnant at apple.com
          Reporter: tuhertz at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130416/6a636e54/attachment.html>
    
    
More information about the llvm-bugs
mailing list