<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - addressof returns wrong address when there is user provided conversion operator to char&"
   href="http://llvm.org/bugs/show_bug.cgi?id=15754">15754</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>addressof returns wrong address when there is user provided conversion operator to char&
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>hhinnant@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>tuhertz@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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:
<a href="http://www.boost.org/doc/libs/release/boost/utility/addressof.hpp">http://www.boost.org/doc/libs/release/boost/utility/addressof.hpp</a>

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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>