commit | c76d2bda6ffc092b4d0471dba00e2f46d2040638 | [log] [tgz] |
---|---|---|
author | Howard Hinnant <hhinnant@apple.com> | Tue Apr 16 17:27:56 2013 +0000 |
committer | Howard Hinnant <hhinnant@apple.com> | Tue Apr 16 17:27:56 2013 +0000 |
tree | fb4e614a4ac653c91233915afda69210eab19710 | |
parent | e10b7b35f82a21a8d9a604f419c11aa074d288b4 [diff] |
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
diff --git a/libcxx/include/memory b/libcxx/include/memory index fe35238..87436ac 100644 --- a/libcxx/include/memory +++ b/libcxx/include/memory
@@ -621,7 +621,7 @@ _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)
diff --git a/libcxx/test/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp b/libcxx/test/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp index 3f1bef1..e07bec4 100644 --- a/libcxx/test/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp +++ b/libcxx/test/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp
@@ -19,8 +19,17 @@ 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 @@ 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)); + } }