From cde357f31846b63e03b52f92db77aa47c09a73fe Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Thu, 30 Aug 2018 08:19:15 +0000 Subject: Merging r340823: ------------------------------------------------------------------------ r340823 | marshall | 2018-08-28 15:29:30 +0200 (Tue, 28 Aug 2018) | 1 line Use addressof instead of operator& in make_shared. Fixes PR38729. As a drive-by, make the same change in raw_storage_iterator (twice). ------------------------------------------------------------------------ --- libcxx/include/memory | 6 +++--- .../memory/storage.iterator/raw_storage_iterator.base.pass.cpp | 8 ++++++++ .../memory/storage.iterator/raw_storage_iterator.pass.cpp | 7 +++++++ .../util.smartptr.shared.create/allocate_shared.pass.cpp | 8 ++++++++ .../util.smartptr.shared.create/make_shared.pass.cpp | 9 +++++++++ 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/libcxx/include/memory b/libcxx/include/memory index a4bf89b495a..adfe4f4fbbe 100644 --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -1989,10 +1989,10 @@ public: _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {} _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;} _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element) - {::new(&*__x_) _Tp(__element); return *this;} + {::new(_VSTD::addressof(*__x_)) _Tp(__element); return *this;} #if _LIBCPP_STD_VER >= 14 _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element) - {::new(&*__x_) _Tp(_VSTD::move(__element)); return *this;} + {::new(_VSTD::addressof(*__x_)) _Tp(_VSTD::move(__element)); return *this;} #endif _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;} _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int) @@ -3682,7 +3682,7 @@ private: virtual void __on_zero_shared_weak() _NOEXCEPT; public: _LIBCPP_INLINE_VISIBILITY - _Tp* get() _NOEXCEPT {return &__data_.second();} + _Tp* get() _NOEXCEPT {return _VSTD::addressof(__data_.second());} }; template diff --git a/libcxx/test/std/utilities/memory/storage.iterator/raw_storage_iterator.base.pass.cpp b/libcxx/test/std/utilities/memory/storage.iterator/raw_storage_iterator.base.pass.cpp index 62a3be80d8b..eb66ed4ad47 100644 --- a/libcxx/test/std/utilities/memory/storage.iterator/raw_storage_iterator.base.pass.cpp +++ b/libcxx/test/std/utilities/memory/storage.iterator/raw_storage_iterator.base.pass.cpp @@ -15,6 +15,13 @@ #include "test_macros.h" +#if TEST_STD_VER >= 11 +#define DELETE_FUNCTION = delete +#else +#define DELETE_FUNCTION +#endif + + int A_constructed = 0; struct A @@ -27,6 +34,7 @@ public: ~A() {--A_constructed; data_ = 0;} bool operator==(int i) const {return data_ == i;} + A* operator& () DELETE_FUNCTION; }; int main() diff --git a/libcxx/test/std/utilities/memory/storage.iterator/raw_storage_iterator.pass.cpp b/libcxx/test/std/utilities/memory/storage.iterator/raw_storage_iterator.pass.cpp index 3df8dd0eded..4d9d698f742 100644 --- a/libcxx/test/std/utilities/memory/storage.iterator/raw_storage_iterator.pass.cpp +++ b/libcxx/test/std/utilities/memory/storage.iterator/raw_storage_iterator.pass.cpp @@ -16,6 +16,12 @@ #include "test_macros.h" #include +#if TEST_STD_VER >= 11 +#define DELETE_FUNCTION = delete +#else +#define DELETE_FUNCTION +#endif + int A_constructed = 0; struct A @@ -28,6 +34,7 @@ public: ~A() {--A_constructed; data_ = 0;} bool operator==(int i) const {return data_ == i;} + A* operator& () DELETE_FUNCTION; }; int main() diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp index 3e4a99e981d..a430b5d796e 100644 --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp @@ -23,6 +23,12 @@ #include "test_allocator.h" #include "min_allocator.h" +#if TEST_STD_VER >= 11 +#define DELETE_FUNCTION = delete +#else +#define DELETE_FUNCTION +#endif + int new_count = 0; struct A @@ -37,6 +43,8 @@ struct A int get_int() const {return int_;} char get_char() const {return char_;} + + A* operator& () DELETE_FUNCTION; private: int int_; char char_; diff --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp index f8f73f77135..88e6919526f 100644 --- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp +++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp @@ -19,6 +19,12 @@ #include "test_macros.h" #include "count_new.hpp" +#if TEST_STD_VER >= 11 +#define DELETE_FUNCTION = delete +#else +#define DELETE_FUNCTION +#endif + struct A { static int count; @@ -31,6 +37,9 @@ struct A int get_int() const {return int_;} char get_char() const {return char_;} + + A* operator& () DELETE_FUNCTION; + private: int int_; char char_; -- cgit v1.2.3