[libcxx-commits] [libcxx] r372780 - [libc++] Remove C++03 variadics in shared_ptr

Zoe Carver via libcxx-commits libcxx-commits at lists.llvm.org
Tue Sep 24 13:55:54 PDT 2019


Author: zoecarver
Date: Tue Sep 24 13:55:54 2019
New Revision: 372780

URL: http://llvm.org/viewvc/llvm-project?rev=372780&view=rev
Log:
    [libc++] Remove C++03 variadics in shared_ptr

    Summary: As suggested by @ldionne in D66178, this patch removes C++03 variadics //only//. Following patches will apply more updates.

    Reviewers: ldionne, EricWF, mclow.lists

    Subscribers: christof, dexonsmith, libcxx-commits, ldionne

    Tags: #libc

    Differential Revision: https://reviews.llvm.org/D67675

Removed:
    libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_cxx03.pass.cpp
Modified:
    libcxx/trunk/include/memory
    libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp
    libcxx/trunk/test/support/min_allocator.h

Modified: libcxx/trunk/include/memory
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=372780&r1=372779&r2=372780&view=diff
==============================================================================
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Tue Sep 24 13:55:54 2019
@@ -3872,8 +3872,6 @@ public:
                       : nullptr);}
 #endif  // _LIBCPP_NO_RTTI
 
-#ifndef _LIBCPP_HAS_NO_VARIADICS
-
     template<class ..._Args>
         static
         shared_ptr<_Tp>
@@ -3884,37 +3882,6 @@ public:
         shared_ptr<_Tp>
         allocate_shared(const _Alloc& __a, _Args&& ...__args);
 
-#else  // _LIBCPP_HAS_NO_VARIADICS
-
-    static shared_ptr<_Tp> make_shared();
-
-    template<class _A0>
-        static shared_ptr<_Tp> make_shared(_A0&);
-
-    template<class _A0, class _A1>
-        static shared_ptr<_Tp> make_shared(_A0&, _A1&);
-
-    template<class _A0, class _A1, class _A2>
-        static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
-
-    template<class _Alloc>
-        static shared_ptr<_Tp>
-        allocate_shared(const _Alloc& __a);
-
-    template<class _Alloc, class _A0>
-        static shared_ptr<_Tp>
-        allocate_shared(const _Alloc& __a, _A0& __a0);
-
-    template<class _Alloc, class _A0, class _A1>
-        static shared_ptr<_Tp>
-        allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
-
-    template<class _Alloc, class _A0, class _A1, class _A2>
-        static shared_ptr<_Tp>
-        allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
-
-#endif  // _LIBCPP_HAS_NO_VARIADICS
-
 private:
     template <class _Yp, bool = is_function<_Yp>::value>
         struct __shared_ptr_default_allocator
@@ -4227,8 +4194,6 @@ shared_ptr<_Tp>::shared_ptr(unique_ptr<_
     __r.release();
 }
 
-#ifndef _LIBCPP_HAS_NO_VARIADICS
-
 template<class _Tp>
 template<class ..._Args>
 shared_ptr<_Tp>
@@ -4268,165 +4233,6 @@ shared_ptr<_Tp>::allocate_shared(const _
     return __r;
 }
 
-#else  // _LIBCPP_HAS_NO_VARIADICS
-
-template<class _Tp>
-shared_ptr<_Tp>
-shared_ptr<_Tp>::make_shared()
-{
-    static_assert((is_constructible<_Tp>::value), "Can't construct object in make_shared" );
-    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
-    typedef allocator<_CntrlBlk> _Alloc2;
-    typedef __allocator_destructor<_Alloc2> _D2;
-    _Alloc2 __alloc2;
-    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
-    ::new(__hold2.get()) _CntrlBlk(__alloc2);
-    shared_ptr<_Tp> __r;
-    __r.__ptr_ = __hold2.get()->get();
-    __r.__cntrl_ = __hold2.release();
-    __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
-    return __r;
-}
-
-template<class _Tp>
-template<class _A0>
-shared_ptr<_Tp>
-shared_ptr<_Tp>::make_shared(_A0& __a0)
-{
-    static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in make_shared" );
-    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
-    typedef allocator<_CntrlBlk> _Alloc2;
-    typedef __allocator_destructor<_Alloc2> _D2;
-    _Alloc2 __alloc2;
-    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
-    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
-    shared_ptr<_Tp> __r;
-    __r.__ptr_ = __hold2.get()->get();
-    __r.__cntrl_ = __hold2.release();
-    __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
-    return __r;
-}
-
-template<class _Tp>
-template<class _A0, class _A1>
-shared_ptr<_Tp>
-shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
-{
-    static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in make_shared" );
-    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
-    typedef allocator<_CntrlBlk> _Alloc2;
-    typedef __allocator_destructor<_Alloc2> _D2;
-    _Alloc2 __alloc2;
-    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
-    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
-    shared_ptr<_Tp> __r;
-    __r.__ptr_ = __hold2.get()->get();
-    __r.__cntrl_ = __hold2.release();
-    __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
-    return __r;
-}
-
-template<class _Tp>
-template<class _A0, class _A1, class _A2>
-shared_ptr<_Tp>
-shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
-{
-    static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in make_shared" );
-    typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
-    typedef allocator<_CntrlBlk> _Alloc2;
-    typedef __allocator_destructor<_Alloc2> _D2;
-    _Alloc2 __alloc2;
-    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
-    ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
-    shared_ptr<_Tp> __r;
-    __r.__ptr_ = __hold2.get()->get();
-    __r.__cntrl_ = __hold2.release();
-    __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
-    return __r;
-}
-
-template<class _Tp>
-template<class _Alloc>
-shared_ptr<_Tp>
-shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
-{
-    static_assert((is_constructible<_Tp>::value), "Can't construct object in allocate_shared" );
-    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
-    typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
-    typedef __allocator_destructor<_Alloc2> _D2;
-    _Alloc2 __alloc2(__a);
-    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
-    ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
-        _CntrlBlk(__a);
-    shared_ptr<_Tp> __r;
-    __r.__ptr_ = __hold2.get()->get();
-    __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
-    __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
-    return __r;
-}
-
-template<class _Tp>
-template<class _Alloc, class _A0>
-shared_ptr<_Tp>
-shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
-{
-    static_assert((is_constructible<_Tp, _A0>::value), "Can't construct object in allocate_shared" );
-    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
-    typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
-    typedef __allocator_destructor<_Alloc2> _D2;
-    _Alloc2 __alloc2(__a);
-    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
-    ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
-        _CntrlBlk(__a, __a0);
-    shared_ptr<_Tp> __r;
-    __r.__ptr_ = __hold2.get()->get();
-    __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
-    __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
-    return __r;
-}
-
-template<class _Tp>
-template<class _Alloc, class _A0, class _A1>
-shared_ptr<_Tp>
-shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
-{
-    static_assert((is_constructible<_Tp, _A0, _A1>::value), "Can't construct object in allocate_shared" );
-    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
-    typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
-    typedef __allocator_destructor<_Alloc2> _D2;
-    _Alloc2 __alloc2(__a);
-    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
-    ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
-        _CntrlBlk(__a, __a0, __a1);
-    shared_ptr<_Tp> __r;
-    __r.__ptr_ = __hold2.get()->get();
-    __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
-    __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
-    return __r;
-}
-
-template<class _Tp>
-template<class _Alloc, class _A0, class _A1, class _A2>
-shared_ptr<_Tp>
-shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
-{
-    static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't construct object in allocate_shared" );
-    typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
-    typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
-    typedef __allocator_destructor<_Alloc2> _D2;
-    _Alloc2 __alloc2(__a);
-    unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
-    ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
-        _CntrlBlk(__a, __a0, __a1, __a2);
-    shared_ptr<_Tp> __r;
-    __r.__ptr_ = __hold2.get()->get();
-    __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
-    __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
-    return __r;
-}
-
-#endif  // _LIBCPP_HAS_NO_VARIADICS
-
 template<class _Tp>
 shared_ptr<_Tp>::~shared_ptr()
 {

Modified: libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp?rev=372780&r1=372779&r2=372780&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp Tue Sep 24 13:55:54 2019
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// UNSUPPORTED: c++98, c++03
-
 // <memory>
 
 // shared_ptr
@@ -52,8 +50,87 @@ private:
 
 int A::count = 0;
 
+struct Zero
+{
+    static int count;
+    Zero() {++count;}
+    Zero(Zero const &) {++count;}
+    ~Zero() {--count;}
+};
+
+int Zero::count = 0;
+
+struct One
+{
+    static int count;
+    int value;
+    explicit One(int v) : value(v) {++count;}
+    One(One const & o) : value(o.value) {++count;}
+    ~One() {--count;}
+};
+
+int One::count = 0;
+
+
+struct Two
+{
+    static int count;
+    int value;
+    Two(int v, int) : value(v) {++count;}
+    Two(Two const & o) : value(o.value) {++count;}
+    ~Two() {--count;}
+};
+
+int Two::count = 0;
+
+struct Three
+{
+    static int count;
+    int value;
+    Three(int v, int, int) : value(v) {++count;}
+    Three(Three const & o) : value(o.value) {++count;}
+    ~Three() {--count;}
+};
+
+int Three::count = 0;
+
+template <class Alloc>
+void test()
+{
+    int const bad = -1;
+    {
+    std::shared_ptr<Zero> p = std::allocate_shared<Zero>(Alloc());
+    assert(Zero::count == 1);
+    }
+    assert(Zero::count == 0);
+    {
+    int const i = 42;
+    std::shared_ptr<One> p = std::allocate_shared<One>(Alloc(), i);
+    assert(One::count == 1);
+    assert(p->value == i);
+    }
+    assert(One::count == 0);
+    {
+    int const i = 42;
+    std::shared_ptr<Two> p = std::allocate_shared<Two>(Alloc(), i, bad);
+    assert(Two::count == 1);
+    assert(p->value == i);
+    }
+    assert(Two::count == 0);
+    {
+    int const i = 42;
+    std::shared_ptr<Three> p = std::allocate_shared<Three>(Alloc(), i, bad, bad);
+    assert(Three::count == 1);
+    assert(p->value == i);
+    }
+    assert(Three::count == 0);
+}
+
 int main(int, char**)
 {
+    test<bare_allocator<void> >();
+    test<test_allocator<void> >();
+
     {
     int i = 67;
     char c = 'e';

Removed: libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_cxx03.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_cxx03.pass.cpp?rev=372779&view=auto
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_cxx03.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_cxx03.pass.cpp (removed)
@@ -1,120 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// shared_ptr
-
-// template<class T, class A, class... Args>
-//    shared_ptr<T> allocate_shared(const A& a, Args&&... args);
-
-
-#include <memory>
-#include <new>
-#include <cstdlib>
-#include <cassert>
-#include "test_macros.h"
-#include "test_allocator.h"
-#include "min_allocator.h"
-
-struct Zero
-{
-    static int count;
-    Zero() {++count;}
-    Zero(Zero const &) {++count;}
-    ~Zero() {--count;}
-};
-
-int Zero::count = 0;
-
-struct One
-{
-    static int count;
-    int value;
-    explicit One(int v) : value(v) {++count;}
-    One(One const & o) : value(o.value) {++count;}
-    ~One() {--count;}
-};
-
-int One::count = 0;
-
-
-struct Two
-{
-    static int count;
-    int value;
-    Two(int v, int) : value(v) {++count;}
-    Two(Two const & o) : value(o.value) {++count;}
-    ~Two() {--count;}
-};
-
-int Two::count = 0;
-
-struct Three
-{
-    static int count;
-    int value;
-    Three(int v, int, int) : value(v) {++count;}
-    Three(Three const & o) : value(o.value) {++count;}
-    ~Three() {--count;}
-};
-
-int Three::count = 0;
-
-template <class Alloc>
-void test()
-{
-    int const bad = -1;
-    {
-    std::shared_ptr<Zero> p = std::allocate_shared<Zero>(Alloc());
-    assert(Zero::count == 1);
-    }
-    assert(Zero::count == 0);
-    {
-    int const i = 42;
-    std::shared_ptr<One> p = std::allocate_shared<One>(Alloc(), i);
-    assert(One::count == 1);
-    assert(p->value == i);
-    }
-    assert(One::count == 0);
-    {
-    int const i = 42;
-    std::shared_ptr<Two> p = std::allocate_shared<Two>(Alloc(), i, bad);
-    assert(Two::count == 1);
-    assert(p->value == i);
-    }
-    assert(Two::count == 0);
-    {
-    int const i = 42;
-    std::shared_ptr<Three> p = std::allocate_shared<Three>(Alloc(), i, bad, bad);
-    assert(Three::count == 1);
-    assert(p->value == i);
-    }
-    assert(Three::count == 0);
-}
-
-int main(int, char**)
-{
-    {
-    int i = 67;
-    int const bad = -1;
-    std::shared_ptr<Two> p = std::allocate_shared<Two>(test_allocator<Two>(54), i, bad);
-    assert(test_allocator<Two>::alloc_count == 1);
-    assert(Two::count == 1);
-    assert(p->value == 67);
-    }
-    assert(Two::count == 0);
-    assert(test_allocator<Two>::alloc_count == 0);
-
-    test<bare_allocator<void> >();
-#if TEST_STD_VER >= 11
-    test<min_allocator<void> >();
-#endif
-
-  return 0;
-}

Modified: libcxx/trunk/test/support/min_allocator.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/min_allocator.h?rev=372780&r1=372779&r2=372780&view=diff
==============================================================================
--- libcxx/trunk/test/support/min_allocator.h (original)
+++ libcxx/trunk/test/support/min_allocator.h Tue Sep 24 13:55:54 2019
@@ -14,6 +14,7 @@
 #include <cstddef>
 #include <cassert>
 #include <climits>
+#include <memory>
 
 #include "test_macros.h"
 
@@ -190,11 +191,6 @@ struct cpp03_overload_allocator : bare_a
 };
 template <class T> bool cpp03_overload_allocator<T>::construct_called = false;
 
-
-#if TEST_STD_VER >= 11
-
-#include <memory>
-
 template <class T, class = std::integral_constant<size_t, 0> > class min_pointer;
 template <class T, class ID> class min_pointer<const T, ID>;
 template <class ID> class min_pointer<void, ID>;
@@ -462,6 +458,4 @@ public:
     friend bool operator!=(explicit_allocator x, explicit_allocator y) {return !(x == y);}
 };
 
-#endif  // TEST_STD_VER >= 11
-
 #endif  // MIN_ALLOCATOR_H




More information about the libcxx-commits mailing list