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:
parent
ae57a1ab1d
commit
4313ec3975
@ -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)
|
||||||
|
@ -19,8 +19,17 @@ 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;
|
||||||
assert(std::addressof(i) == &i);
|
assert(std::addressof(i) == &i);
|
||||||
@ -30,4 +39,13 @@ int main()
|
|||||||
assert(std::addressof(*tp) == tp);
|
assert(std::addressof(*tp) == tp);
|
||||||
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user