Use addressof instead of operator& in make_shared. Fixes PR38729. As a drive-by, make the same change in raw_storage_iterator (twice).

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@340823 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2018-08-28 13:29:30 +00:00
parent f45b25b18d
commit c4f0f1eaa8
5 changed files with 35 additions and 3 deletions

View File

@@ -1989,10 +1989,10 @@ public:
_LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {} _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*() {return *this;}
_LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element) _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 #if _LIBCPP_STD_VER >= 14
_LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element) _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 #endif
_LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;} _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
_LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int) _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
@@ -3682,7 +3682,7 @@ private:
virtual void __on_zero_shared_weak() _NOEXCEPT; virtual void __on_zero_shared_weak() _NOEXCEPT;
public: public:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_INLINE_VISIBILITY
_Tp* get() _NOEXCEPT {return &__data_.second();} _Tp* get() _NOEXCEPT {return _VSTD::addressof(__data_.second());}
}; };
template <class _Tp, class _Alloc> template <class _Tp, class _Alloc>

View File

@@ -15,6 +15,13 @@
#include "test_macros.h" #include "test_macros.h"
#if TEST_STD_VER >= 11
#define DELETE_FUNCTION = delete
#else
#define DELETE_FUNCTION
#endif
int A_constructed = 0; int A_constructed = 0;
struct A struct A
@@ -27,6 +34,7 @@ public:
~A() {--A_constructed; data_ = 0;} ~A() {--A_constructed; data_ = 0;}
bool operator==(int i) const {return data_ == i;} bool operator==(int i) const {return data_ == i;}
A* operator& () DELETE_FUNCTION;
}; };
int main() int main()

View File

@@ -16,6 +16,12 @@
#include "test_macros.h" #include "test_macros.h"
#include <MoveOnly.h> #include <MoveOnly.h>
#if TEST_STD_VER >= 11
#define DELETE_FUNCTION = delete
#else
#define DELETE_FUNCTION
#endif
int A_constructed = 0; int A_constructed = 0;
struct A struct A
@@ -28,6 +34,7 @@ public:
~A() {--A_constructed; data_ = 0;} ~A() {--A_constructed; data_ = 0;}
bool operator==(int i) const {return data_ == i;} bool operator==(int i) const {return data_ == i;}
A* operator& () DELETE_FUNCTION;
}; };
int main() int main()

View File

@@ -23,6 +23,12 @@
#include "test_allocator.h" #include "test_allocator.h"
#include "min_allocator.h" #include "min_allocator.h"
#if TEST_STD_VER >= 11
#define DELETE_FUNCTION = delete
#else
#define DELETE_FUNCTION
#endif
int new_count = 0; int new_count = 0;
struct A struct A
@@ -37,6 +43,8 @@ struct A
int get_int() const {return int_;} int get_int() const {return int_;}
char get_char() const {return char_;} char get_char() const {return char_;}
A* operator& () DELETE_FUNCTION;
private: private:
int int_; int int_;
char char_; char char_;

View File

@@ -19,6 +19,12 @@
#include "test_macros.h" #include "test_macros.h"
#include "count_new.hpp" #include "count_new.hpp"
#if TEST_STD_VER >= 11
#define DELETE_FUNCTION = delete
#else
#define DELETE_FUNCTION
#endif
struct A struct A
{ {
static int count; static int count;
@@ -31,6 +37,9 @@ struct A
int get_int() const {return int_;} int get_int() const {return int_;}
char get_char() const {return char_;} char get_char() const {return char_;}
A* operator& () DELETE_FUNCTION;
private: private:
int int_; int int_;
char char_; char char_;