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
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: c76d2bda6ffc092b4d0471dba00e2f46d2040638
diff --git a/include/memory b/include/memory
index fe35238..87436ac 100644
--- a/include/memory
+++ b/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/test/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp b/test/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp
index 3f1bef1..e07bec4 100644
--- a/test/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp
+++ b/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));
+    }
 }