summaryrefslogtreecommitdiffstats
path: root/libcxx/test
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/test')
-rw-r--r--libcxx/test/std/strings/basic.string/string.cons/alloc.pass.cpp25
-rw-r--r--libcxx/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp6
-rw-r--r--libcxx/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp23
-rw-r--r--libcxx/test/std/strings/basic.string/string.cons/move_noexcept.pass.cpp5
-rw-r--r--libcxx/test/support/allocators.h24
-rw-r--r--libcxx/test/support/min_allocator.h28
-rw-r--r--libcxx/test/support/test_allocator.h2
7 files changed, 86 insertions, 27 deletions
diff --git a/libcxx/test/std/strings/basic.string/string.cons/alloc.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/alloc.pass.cpp
index 512d1182755..1c4f2044834 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/alloc.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/alloc.pass.cpp
@@ -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
}
diff --git a/libcxx/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp
index f935db83d73..c6137d6b54b 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/default_noexcept.pass.cpp
@@ -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
}
diff --git a/libcxx/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp
index 1f9631449ee..a232a46bd9f 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/move_alloc.pass.cpp
@@ -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_type& a)
}
#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());
diff --git a/libcxx/test/std/strings/basic.string/string.cons/move_noexcept.pass.cpp b/libcxx/test/std/strings/basic.string/string.cons/move_noexcept.pass.cpp
index 556aabdc44a..b287a940cc8 100644
--- a/libcxx/test/std/strings/basic.string/string.cons/move_noexcept.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/string.cons/move_noexcept.pass.cpp
@@ -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
}
diff --git a/libcxx/test/support/allocators.h b/libcxx/test/support/allocators.h
index 5372c073054..b7aba12e21f 100644
--- a/libcxx/test/support/allocators.h
+++ b/libcxx/test/support/allocators.h
@@ -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)
diff --git a/libcxx/test/support/min_allocator.h b/libcxx/test/support/min_allocator.h
index b643636e178..5e3ae5d2a13 100644
--- a/libcxx/test/support/min_allocator.h
+++ b/libcxx/test/support/min_allocator.h
@@ -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_)) {}
diff --git a/libcxx/test/support/test_allocator.h b/libcxx/test/support/test_allocator.h
index 683fac239f2..03bd3905606 100644
--- a/libcxx/test/support/test_allocator.h
+++ b/libcxx/test/support/test_allocator.h
@@ -17,6 +17,8 @@
#include <climits>
#include <cassert>
+#include "test_macros.h"
+
class test_alloc_base
{
protected:
OpenPOWER on IntegriCloud