forked from OSchip/llvm-project
addressof misbehaving for type with an implicit conversion operator to char&. This fixes http://llvm.org/bugs/show_bug.cgi?id=15754
llvm-svn: 179608
This commit is contained in:
parent
e10b7b35f8
commit
c76d2bda6f
|
@ -621,7 +621,7 @@ inline _LIBCPP_INLINE_VISIBILITY
|
|||
_Tp*
|
||||
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)
|
||||
|
|
|
@ -19,8 +19,17 @@ struct A
|
|||
void operator&() const {}
|
||||
};
|
||||
|
||||
struct nothing {
|
||||
operator char&()
|
||||
{
|
||||
static char c;
|
||||
return c;
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
int i;
|
||||
double d;
|
||||
assert(std::addressof(i) == &i);
|
||||
|
@ -30,4 +39,13 @@ int main()
|
|||
assert(std::addressof(*tp) == tp);
|
||||
assert(std::addressof(*ctp) == tp);
|
||||
delete tp;
|
||||
}
|
||||
{
|
||||
union
|
||||
{
|
||||
nothing n;
|
||||
int i;
|
||||
};
|
||||
assert(std::addressof(n) == (void*)std::addressof(i));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue