[libcxx] r238957 - More of N4258 implementation. Mark all of our test_allocators as noexcept constructible. Make the constructors for basic_string noexcept all the time (under C++14). Update tests to reflect the new world order. More to come.

Marshall Clow mclow.lists at gmail.com
Wed Jun 3 12:56:43 PDT 2015


Author: marshall
Date: Wed Jun  3 14:56:43 2015
New Revision: 238957

URL: http://llvm.org/viewvc/llvm-project?rev=238957&view=rev
Log:
More of N4258 implementation. Mark all of our test_allocators as noexcept constructible. Make the constructors for basic_string noexcept all the time (under C++14). Update tests to reflect the new world order. More to come.

Modified:
    libcxx/trunk/include/string
    libcxx/trunk/test/std/strings/basic.string/string.cons/alloc.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp
    libcxx/trunk/test/std/strings/basic.string/string.cons/move_noexcept.pass.cpp
    libcxx/trunk/test/support/allocators.h
    libcxx/trunk/test/support/min_allocator.h
    libcxx/trunk/test/support/test_allocator.h

Modified: libcxx/trunk/include/string
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=238957&r1=238956&r2=238957&view=diff
==============================================================================
--- libcxx/trunk/include/string (original)
+++ libcxx/trunk/include/string Wed Jun  3 14:56:43 2015
@@ -1321,14 +1321,31 @@ public:
     static const size_type npos = -1;
 
     _LIBCPP_INLINE_VISIBILITY basic_string()
+#if _LIBCPP_STD_VER <= 14
         _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
-    _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a);
+#else
+        _NOEXCEPT;
+#endif
+
+    _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
+#if _LIBCPP_STD_VER <= 14
+        _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
+#else
+        _NOEXCEPT;
+#endif
+
     basic_string(const basic_string& __str);
     basic_string(const basic_string& __str, const allocator_type& __a);
+
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     _LIBCPP_INLINE_VISIBILITY
     basic_string(basic_string&& __str)
+#if _LIBCPP_STD_VER <= 14
         _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
+#else
+        _NOEXCEPT;
+#endif
+
     _LIBCPP_INLINE_VISIBILITY
     basic_string(basic_string&& __str, const allocator_type& __a);
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -1926,7 +1943,11 @@ basic_string<_CharT, _Traits, _Allocator
 template <class _CharT, class _Traits, class _Allocator>
 inline _LIBCPP_INLINE_VISIBILITY
 basic_string<_CharT, _Traits, _Allocator>::basic_string()
-    _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
+#if _LIBCPP_STD_VER <= 14
+        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
+#else
+        _NOEXCEPT
+#endif
 {
 #if _LIBCPP_DEBUG_LEVEL >= 2
     __get_db()->__insert_c(this);
@@ -2070,7 +2091,11 @@ basic_string<_CharT, _Traits, _Allocator
 template <class _CharT, class _Traits, class _Allocator>
 inline _LIBCPP_INLINE_VISIBILITY
 basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
+#if _LIBCPP_STD_VER <= 14
         _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
+#else
+        _NOEXCEPT
+#endif
     : __r_(_VSTD::move(__str.__r_))
 {
     __str.__zero();

Modified: libcxx/trunk/test/std/strings/basic.string/string.cons/alloc.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/alloc.pass.cpp?rev=238957&r1=238956&r2=238957&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/alloc.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/alloc.pass.cpp Wed Jun  3 14:56:43 2015
@@ -14,6 +14,7 @@
 #include <string>
 #include <cassert>
 
+#include "test_macros.h"
 #include "test_allocator.h"
 #include "min_allocator.h"
 
@@ -22,6 +23,11 @@ void
 test()
 {
     {
+#if TEST_STD_VER > 14
+	static_assert((noexcept(S{})), "" );
+#elif TEST_STD_VER >= 11
+	static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" );
+#endif
     S s;
     assert(s.__invariants());
     assert(s.data());
@@ -30,6 +36,11 @@ test()
     assert(s.get_allocator() == typename S::allocator_type());
     }
     {
+#if TEST_STD_VER > 14
+	static_assert((noexcept(S{typename S::allocator_type{}})), "" );
+#elif TEST_STD_VER >= 11
+	static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" );
+#endif
     S s(typename S::allocator_type(5));
     assert(s.__invariants());
     assert(s.data());
@@ -39,13 +50,18 @@ test()
     }
 }
 
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
 
 template <class S>
 void
 test2()
 {
     {
+#if TEST_STD_VER > 14
+	static_assert((noexcept(S{})), "" );
+#elif TEST_STD_VER >= 11
+	static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" );
+#endif
     S s;
     assert(s.__invariants());
     assert(s.data());
@@ -54,6 +70,11 @@ test2()
     assert(s.get_allocator() == typename S::allocator_type());
     }
     {
+#if TEST_STD_VER > 14
+	static_assert((noexcept(S{typename S::allocator_type{}})), "" );
+#elif TEST_STD_VER >= 11
+	static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" );
+#endif
     S s(typename S::allocator_type{});
     assert(s.__invariants());
     assert(s.data());
@@ -68,7 +89,7 @@ test2()
 int main()
 {
     test<std::basic_string<char, std::char_traits<char>, test_allocator<char> > >();
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
     test2<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
 #endif
 }

Modified: libcxx/trunk/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp?rev=238957&r1=238956&r2=238957&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp Wed Jun  3 14:56:43 2015
@@ -17,6 +17,7 @@
 #include <string>
 #include <cassert>
 
+#include "test_macros.h"
 #include "test_allocator.h"
 
 template <class T>
@@ -39,7 +40,12 @@ int main()
     }
     {
         typedef std::basic_string<char, std::char_traits<char>, some_alloc<char>> C;
+// See N4258 - basic_string<char, traits, Allocator>::basic_string() noexcept;
+#if TEST_STD_VER <= 14
         static_assert(!std::is_nothrow_default_constructible<C>::value, "");
+#else
+        static_assert( std::is_nothrow_default_constructible<C>::value, "");
+#endif
     }
 #endif
 }

Modified: libcxx/trunk/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp?rev=238957&r1=238956&r2=238957&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp Wed Jun  3 14:56:43 2015
@@ -16,6 +16,7 @@
 
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
+#include "test_macros.h"
 #include "test_allocator.h"
 #include "min_allocator.h"
 
@@ -34,6 +35,11 @@ test(S s0, const typename S::allocator_t
 }
 
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+// #if _LIBCPP_STD_VER <= 14
+//         _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
+// #else
+//         _NOEXCEPT;
+// #endif
 
 int main()
 {
@@ -41,6 +47,11 @@ int main()
     {
     typedef test_allocator<char> A;
     typedef std::basic_string<char, std::char_traits<char>, A> S;
+#if TEST_STD_VER > 14
+	static_assert((noexcept(S{})), "" );
+#elif TEST_STD_VER >= 11
+	static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
+#endif
     test(S(), A(3));
     test(S("1"), A(5));
     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7));
@@ -50,15 +61,25 @@ int main()
     {
     typedef test_allocator<char> A;
     typedef std::basic_string<char, std::char_traits<char>, A> S;
+#if TEST_STD_VER > 14
+	static_assert((noexcept(S{})), "" );
+#elif TEST_STD_VER >= 11
+	static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
+#endif
     S s1 ( "Twas brillig, and the slivy toves did gyre and gymbal in the wabe" );
     S s2 (std::move(s1), A(1));
     }
     assert ( test_alloc_base::alloc_count == alloc_count );
     
-#if __cplusplus >= 201103L
+#if TEST_STD_VER >= 11
     {
     typedef min_allocator<char> A;
     typedef std::basic_string<char, std::char_traits<char>, A> S;
+#if TEST_STD_VER > 14
+	static_assert((noexcept(S{})), "" );
+#elif TEST_STD_VER >= 11
+	static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
+#endif
     test(S(), A());
     test(S("1"), A());
     test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A());

Modified: libcxx/trunk/test/std/strings/basic.string/string.cons/move_noexcept.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/move_noexcept.pass.cpp?rev=238957&r1=238956&r2=238957&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.cons/move_noexcept.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/move_noexcept.pass.cpp Wed Jun  3 14:56:43 2015
@@ -17,6 +17,7 @@
 #include <string>
 #include <cassert>
 
+#include "test_macros.h"
 #include "test_allocator.h"
 
 template <class T>
@@ -39,7 +40,11 @@ int main()
     }
     {
         typedef std::basic_string<char, std::char_traits<char>, some_alloc<char>> C;
+#if TEST_STD_VER <= 14
         static_assert(!std::is_nothrow_move_constructible<C>::value, "");
+#else
+        static_assert( std::is_nothrow_move_constructible<C>::value, "");
+#endif
     }
 #endif
 }

Modified: libcxx/trunk/test/support/allocators.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/allocators.h?rev=238957&r1=238956&r2=238957&view=diff
==============================================================================
--- libcxx/trunk/test/support/allocators.h (original)
+++ libcxx/trunk/test/support/allocators.h Wed Jun  3 14:56:43 2015
@@ -13,6 +13,8 @@
 #include <type_traits>
 #include <utility>
 
+#include "test_macros.h"
+
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template <class T>
@@ -20,7 +22,7 @@ class A1
 {
     int id_;
 public:
-    explicit A1(int id = 0) : id_(id) {}
+    explicit A1(int id = 0) TEST_NOEXCEPT : id_(id) {}
 
     typedef T value_type;
 
@@ -31,13 +33,13 @@ public:
     static bool allocate_called;
     static std::pair<T*, std::size_t> deallocate_called;
 
-    A1(const A1& a) : id_(a.id()) {copy_called = true;}
-    A1(A1&& a) : id_(a.id())      {move_called = true;}
+    A1(const A1& a) TEST_NOEXCEPT : id_(a.id()) {copy_called = true;}
+    A1(A1&& a)      TEST_NOEXCEPT : id_(a.id()) {move_called = true;}
 
     template <class U>
-        A1(const A1<U>& a) : id_(a.id()) {copy_called = true;}
+        A1(const A1<U>& a) TEST_NOEXCEPT : id_(a.id()) {copy_called = true;}
     template <class U>
-        A1(A1<U>&& a) : id_(a.id()) {move_called = true;}
+        A1(A1<U>&& a) TEST_NOEXCEPT : id_(a.id()) {move_called = true;}
 
     T* allocate(std::size_t n)
     {
@@ -77,7 +79,7 @@ class A2
 {
     int id_;
 public:
-    explicit A2(int id = 0) : id_(id) {}
+    explicit A2(int id = 0) TEST_NOEXCEPT : id_(id) {}
 
     typedef T value_type;
 
@@ -92,8 +94,8 @@ public:
     static bool move_called;
     static bool allocate_called;
 
-    A2(const A2& a) : id_(a.id()) {copy_called = true;}
-    A2(A2&& a) : id_(a.id())      {move_called = true;}
+    A2(const A2& a) TEST_NOEXCEPT : id_(a.id()) {copy_called = true;}
+    A2(A2&& a)      TEST_NOEXCEPT : id_(a.id()) {move_called = true;}
 
     T* allocate(std::size_t n, const void* hint)
     {
@@ -125,7 +127,7 @@ class A3
 {
     int id_;
 public:
-    explicit A3(int id = 0) : id_(id) {}
+    explicit A3(int id = 0) TEST_NOEXCEPT : id_(id) {}
 
     typedef T value_type;
 
@@ -139,8 +141,8 @@ public:
     static bool constructed;
     static bool destroy_called;
 
-    A3(const A3& a) : id_(a.id()) {copy_called = true;}
-    A3(A3&& a) : id_(a.id())      {move_called = true;}
+    A3(const A3& a) TEST_NOEXCEPT : id_(a.id()) {copy_called = true;}
+    A3(A3&& a)      TEST_NOEXCEPT: id_(a.id())  {move_called = true;}
 
     template <class U, class ...Args>
     void construct(U* p, Args&& ...args)

Modified: libcxx/trunk/test/support/min_allocator.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/min_allocator.h?rev=238957&r1=238956&r2=238957&view=diff
==============================================================================
--- libcxx/trunk/test/support/min_allocator.h (original)
+++ libcxx/trunk/test/support/min_allocator.h Wed Jun  3 14:56:43 2015
@@ -12,16 +12,18 @@
 
 #include <cstddef>
 
+#include "test_macros.h"
+
 template <class T>
 class bare_allocator
 {
 public:
     typedef T value_type;
 
-    bare_allocator() {}
+    bare_allocator() TEST_NOEXCEPT {}
 
     template <class U>
-    bare_allocator(bare_allocator<U>) {}
+    bare_allocator(bare_allocator<U>) TEST_NOEXCEPT {}
 
     T* allocate(std::size_t n)
     {
@@ -53,10 +55,10 @@ class min_pointer<const void>
 {
     const void* ptr_;
 public:
-    min_pointer() noexcept = default;
-    min_pointer(std::nullptr_t) : ptr_(nullptr) {}
+    min_pointer() TEST_NOEXCEPT = default;
+    min_pointer(std::nullptr_t) TEST_NOEXCEPT : ptr_(nullptr) {}
     template <class T>
-    min_pointer(min_pointer<T> p) : ptr_(p.ptr_) {}
+    min_pointer(min_pointer<T> p) TEST_NOEXCEPT : ptr_(p.ptr_) {}
 
     explicit operator bool() const {return ptr_ != nullptr;}
 
@@ -70,15 +72,15 @@ class min_pointer<void>
 {
     void* ptr_;
 public:
-    min_pointer() noexcept = default;
-    min_pointer(std::nullptr_t) : ptr_(nullptr) {}
+    min_pointer() TEST_NOEXCEPT = default;
+    min_pointer(std::nullptr_t) TEST_NOEXCEPT : ptr_(nullptr) {}
     template <class T,
               class = typename std::enable_if
                        <
                             !std::is_const<T>::value
                        >::type
              >
-    min_pointer(min_pointer<T> p) : ptr_(p.ptr_) {}
+    min_pointer(min_pointer<T> p) TEST_NOEXCEPT : ptr_(p.ptr_) {}
 
     explicit operator bool() const {return ptr_ != nullptr;}
 
@@ -92,11 +94,11 @@ class min_pointer
 {
     T* ptr_;
 
-    explicit min_pointer(T* p) : ptr_(p) {}
+    explicit min_pointer(T* p) TEST_NOEXCEPT : ptr_(p) {}
 public:
-    min_pointer() noexcept = default;
-    min_pointer(std::nullptr_t) : ptr_(nullptr) {}
-    explicit min_pointer(min_pointer<void> p) : ptr_(static_cast<T*>(p.ptr_)) {}
+    min_pointer() TEST_NOEXCEPT = default;
+    min_pointer(std::nullptr_t) TEST_NOEXCEPT : ptr_(nullptr) {}
+    explicit min_pointer(min_pointer<void> p) TEST_NOEXCEPT : ptr_(static_cast<T*>(p.ptr_)) {}
 
     explicit operator bool() const {return ptr_ != nullptr;}
 
@@ -164,7 +166,7 @@ class min_pointer<const T>
 
     explicit min_pointer(const T* p) : ptr_(p) {}
 public:
-    min_pointer() noexcept = default;
+    min_pointer() TEST_NOEXCEPT = default;
     min_pointer(std::nullptr_t) : ptr_(nullptr) {}
     min_pointer(min_pointer<T> p) : ptr_(p.ptr_) {}
     explicit min_pointer(min_pointer<const void> p) : ptr_(static_cast<const T*>(p.ptr_)) {}

Modified: libcxx/trunk/test/support/test_allocator.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/test_allocator.h?rev=238957&r1=238956&r2=238957&view=diff
==============================================================================
--- libcxx/trunk/test/support/test_allocator.h (original)
+++ libcxx/trunk/test/support/test_allocator.h Wed Jun  3 14:56:43 2015
@@ -17,6 +17,8 @@
 #include <climits>
 #include <cassert>
 
+#include "test_macros.h"
+
 class test_alloc_base
 {
 protected:





More information about the cfe-commits mailing list