addressof misbehaving for type with an implicit conversion operator to char&. This fixes http://llvm.org/bugs/show_bug.cgi?id=15754

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@179608 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant 2013-04-16 17:27:56 +00:00
parent ae57a1ab1d
commit 4313ec3975
2 changed files with 19 additions and 1 deletions

View File

@ -621,7 +621,7 @@ inline _LIBCPP_INLINE_VISIBILITY
_Tp* _Tp*
addressof(_Tp& __x) _NOEXCEPT addressof(_Tp& __x) _NOEXCEPT
{ {
return (_Tp*)&(char&)__x; return (_Tp*)&reinterpret_cast<const volatile char&>(__x);
} }
#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF) #if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)

View File

@ -19,7 +19,16 @@ struct A
void operator&() const {} void operator&() const {}
}; };
struct nothing {
operator char&()
{
static char c;
return c;
}
};
int main() int main()
{
{ {
int i; int i;
double d; double d;
@ -31,3 +40,12 @@ int main()
assert(std::addressof(*ctp) == tp); assert(std::addressof(*ctp) == tp);
delete tp; delete tp;
} }
{
union
{
nothing n;
int i;
};
assert(std::addressof(n) == (void*)std::addressof(i));
}
}