aboutsummaryrefslogtreecommitdiffstats
path: root/test/std
diff options
context:
space:
mode:
Diffstat (limited to 'test/std')
-rw-r--r--test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp37
-rw-r--r--test/std/experimental/filesystem/fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp126
-rw-r--r--test/std/re/re.iter/re.regiter/re.regiter.incr/post.pass.cpp18
-rw-r--r--test/std/thread/futures/futures.task/futures.task.members/ctor2.fail.cpp2
-rw-r--r--test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp5
-rw-r--r--test/std/utilities/optional/optional.object/optional.object.assign/move.pass.cpp30
-rw-r--r--test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp8
-rw-r--r--test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp8
-rw-r--r--test/std/utilities/optional/optional.object/special_member_gen.pass.cpp36
9 files changed, 187 insertions, 83 deletions
diff --git a/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp b/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp
index e42e9f28448a..7a4090b9c252 100644
--- a/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp
+++ b/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp
@@ -25,6 +25,40 @@ template <typename T> void checkAlwaysLockFree() {
assert(std::atomic<T>().is_lock_free());
}
+// FIXME: This separate test is needed to work around llvm.org/PR31864
+// which causes ATOMIC_LLONG_LOCK_FREE to be defined as '1' in 32-bit builds
+// even though __atomic_always_lock_free returns true for the same type.
+constexpr bool NeedWorkaroundForPR31864 =
+#if defined(__clang__)
+(sizeof(void*) == 4); // Needed on 32 bit builds
+#else
+false;
+#endif
+
+template <bool Disable = NeedWorkaroundForPR31864,
+ std::enable_if_t<!Disable>* = nullptr,
+ class LLong = long long,
+ class ULLong = unsigned long long>
+void checkLongLongTypes() {
+ static_assert(std::atomic<LLong>::is_always_lock_free == (2 == ATOMIC_LLONG_LOCK_FREE));
+ static_assert(std::atomic<ULLong>::is_always_lock_free == (2 == ATOMIC_LLONG_LOCK_FREE));
+}
+
+// Used to make the calls to __atomic_always_lock_free dependent on a template
+// parameter.
+template <class T> constexpr size_t getSizeOf() { return sizeof(T); }
+
+template <bool Enable = NeedWorkaroundForPR31864,
+ std::enable_if_t<Enable>* = nullptr,
+ class LLong = long long,
+ class ULLong = unsigned long long>
+void checkLongLongTypes() {
+ constexpr bool ExpectLockFree = __atomic_always_lock_free(getSizeOf<LLong>(), 0);
+ static_assert(std::atomic<LLong>::is_always_lock_free == ExpectLockFree, "");
+ static_assert(std::atomic<ULLong>::is_always_lock_free == ExpectLockFree, "");
+ static_assert((0 != ATOMIC_LLONG_LOCK_FREE) == ExpectLockFree, "");
+}
+
int main()
{
// structs and unions can't be defined in the template invocation.
@@ -94,8 +128,7 @@ int main()
static_assert(std::atomic<unsigned int>::is_always_lock_free == (2 == ATOMIC_INT_LOCK_FREE));
static_assert(std::atomic<long>::is_always_lock_free == (2 == ATOMIC_LONG_LOCK_FREE));
static_assert(std::atomic<unsigned long>::is_always_lock_free == (2 == ATOMIC_LONG_LOCK_FREE));
- static_assert(std::atomic<long long>::is_always_lock_free == (2 == ATOMIC_LLONG_LOCK_FREE));
- static_assert(std::atomic<unsigned long long>::is_always_lock_free == (2 == ATOMIC_LLONG_LOCK_FREE));
+ checkLongLongTypes();
static_assert(std::atomic<void*>::is_always_lock_free == (2 == ATOMIC_POINTER_LOCK_FREE));
static_assert(std::atomic<std::nullptr_t>::is_always_lock_free == (2 == ATOMIC_POINTER_LOCK_FREE));
}
diff --git a/test/std/experimental/filesystem/fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp b/test/std/experimental/filesystem/fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp
index 621ff8305fc3..a3591e0267e6 100644
--- a/test/std/experimental/filesystem/fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp
+++ b/test/std/experimental/filesystem/fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp
@@ -26,63 +26,87 @@ using namespace std::experimental::filesystem;
TEST_SUITE(equivalent_test_suite)
-TEST_CASE(signature_test)
-{
- const path p; ((void)p);
- std::error_code ec; ((void)ec);
- ASSERT_NOEXCEPT(equivalent(p, p, ec));
- ASSERT_NOT_NOEXCEPT(equivalent(p, p));
+TEST_CASE(signature_test) {
+ const path p;
+ ((void)p);
+ std::error_code ec;
+ ((void)ec);
+ ASSERT_NOEXCEPT(equivalent(p, p, ec));
+ ASSERT_NOT_NOEXCEPT(equivalent(p, p));
}
-TEST_CASE(equivalent_test)
-{
- struct TestCase {
- path lhs;
- path rhs;
- bool expect;
- };
- const TestCase testCases[] = {
- {StaticEnv::Dir, StaticEnv::Dir, true},
- {StaticEnv::File, StaticEnv::Dir, false},
- {StaticEnv::Dir, StaticEnv::SymlinkToDir, true},
- {StaticEnv::Dir, StaticEnv::SymlinkToFile, false},
- {StaticEnv::File, StaticEnv::File, true},
- {StaticEnv::File, StaticEnv::SymlinkToFile, true},
- };
- for (auto& TC : testCases) {
- std::error_code ec;
- TEST_CHECK(equivalent(TC.lhs, TC.rhs, ec) == TC.expect);
- TEST_CHECK(!ec);
- }
+TEST_CASE(equivalent_test) {
+ struct TestCase {
+ path lhs;
+ path rhs;
+ bool expect;
+ };
+ const TestCase testCases[] = {
+ {StaticEnv::Dir, StaticEnv::Dir, true},
+ {StaticEnv::File, StaticEnv::Dir, false},
+ {StaticEnv::Dir, StaticEnv::SymlinkToDir, true},
+ {StaticEnv::Dir, StaticEnv::SymlinkToFile, false},
+ {StaticEnv::File, StaticEnv::File, true},
+ {StaticEnv::File, StaticEnv::SymlinkToFile, true},
+ };
+ for (auto& TC : testCases) {
+ std::error_code ec;
+ TEST_CHECK(equivalent(TC.lhs, TC.rhs, ec) == TC.expect);
+ TEST_CHECK(!ec);
+ }
}
-TEST_CASE(equivalent_reports_double_dne)
-{
- const path E = StaticEnv::File;
- const path DNE = StaticEnv::DNE;
- { // Test that no exception is thrown if one of the paths exists
- TEST_CHECK(equivalent(E, DNE) == false);
- TEST_CHECK(equivalent(DNE, E) == false);
- }
- { // Test that an exception is thrown if both paths do not exist.
- TEST_CHECK_THROW(filesystem_error, equivalent(DNE, DNE));
- }
- {
- std::error_code ec;
- TEST_CHECK(equivalent(DNE, DNE, ec) == false);
- TEST_CHECK(ec);
- }
+TEST_CASE(equivalent_reports_error_if_input_dne) {
+ const path E = StaticEnv::File;
+ const path DNE = StaticEnv::DNE;
+ { // Test that an error is reported when either of the paths don't exist
+ std::error_code ec = GetTestEC();
+ TEST_CHECK(equivalent(E, DNE, ec) == false);
+ TEST_CHECK(ec);
+ TEST_CHECK(ec != GetTestEC());
+ }
+ {
+ std::error_code ec = GetTestEC();
+ TEST_CHECK(equivalent(DNE, E, ec) == false);
+ TEST_CHECK(ec);
+ TEST_CHECK(ec != GetTestEC());
+ }
+ {
+ TEST_CHECK_THROW(filesystem_error, equivalent(DNE, E));
+ TEST_CHECK_THROW(filesystem_error, equivalent(E, DNE));
+ }
+ { // Test that an exception is thrown if both paths do not exist.
+ TEST_CHECK_THROW(filesystem_error, equivalent(DNE, DNE));
+ }
+ {
+ std::error_code ec = GetTestEC();
+ TEST_CHECK(equivalent(DNE, DNE, ec) == false);
+ TEST_CHECK(ec);
+ TEST_CHECK(ec != GetTestEC());
+ }
}
-TEST_CASE(equivalent_is_other_succeeds)
-{
- scoped_test_env env;
- path const file = env.create_file("file", 42);
- const path hl1 = env.create_hardlink(file, "hl1");
- const path hl2 = env.create_hardlink(file, "hl2");
- TEST_CHECK(equivalent(file, hl1));
- TEST_CHECK(equivalent(file, hl2));
- TEST_CHECK(equivalent(hl1, hl2));
+TEST_CASE(equivalent_hardlink_succeeds) {
+ scoped_test_env env;
+ path const file = env.create_file("file", 42);
+ const path hl1 = env.create_hardlink(file, "hl1");
+ const path hl2 = env.create_hardlink(file, "hl2");
+ TEST_CHECK(equivalent(file, hl1));
+ TEST_CHECK(equivalent(file, hl2));
+ TEST_CHECK(equivalent(hl1, hl2));
+}
+
+TEST_CASE(equivalent_is_other_succeeds) {
+ scoped_test_env env;
+ path const file = env.create_file("file", 42);
+ const path fifo1 = env.create_fifo("fifo1");
+ const path fifo2 = env.create_fifo("fifo2");
+ // Required to test behavior for inputs where is_other(p) is true.
+ TEST_REQUIRE(is_other(fifo1));
+ TEST_CHECK(!equivalent(file, fifo1));
+ TEST_CHECK(!equivalent(fifo2, file));
+ TEST_CHECK(!equivalent(fifo1, fifo2));
+ TEST_CHECK(equivalent(fifo1, fifo1));
}
TEST_SUITE_END()
diff --git a/test/std/re/re.iter/re.regiter/re.regiter.incr/post.pass.cpp b/test/std/re/re.iter/re.regiter/re.regiter.incr/post.pass.cpp
index f3b57f6bc9da..5e3ad4d910e7 100644
--- a/test/std/re/re.iter/re.regiter/re.regiter.incr/post.pass.cpp
+++ b/test/std/re/re.iter/re.regiter/re.regiter.incr/post.pass.cpp
@@ -95,4 +95,22 @@ int main()
assert((*i2).position() == 0);
assert((*i2).str() == "555-1234");
}
+ { // http://llvm.org/PR33681
+ std::regex rex(".*");
+ const char foo[] = "foo";
+ // The -1 is because we don't want the implicit null from the array.
+ std::cregex_iterator i(std::begin(foo), std::end(foo) - 1, rex);
+ std::cregex_iterator e;
+ assert(i != e);
+ assert((*i).size() == 1);
+ assert((*i).str() == "foo");
+
+ ++i;
+ assert(i != e);
+ assert((*i).size() == 1);
+ assert((*i).str() == "");
+
+ ++i;
+ assert(i == e);
+ }
}
diff --git a/test/std/thread/futures/futures.task/futures.task.members/ctor2.fail.cpp b/test/std/thread/futures/futures.task/futures.task.members/ctor2.fail.cpp
index 984dcdc80b32..212a12084e79 100644
--- a/test/std/thread/futures/futures.task/futures.task.members/ctor2.fail.cpp
+++ b/test/std/thread/futures/futures.task/futures.task.members/ctor2.fail.cpp
@@ -30,5 +30,5 @@ typedef volatile std::packaged_task<A(int, char)> VPT;
int main()
{
PT p { std::allocator_arg_t{}, test_allocator<A>{}, VPT {}}; // expected-error {{no matching constructor for initialization of 'PT' (aka 'packaged_task<A (int, char)>')}}
- // expected-note@future:* 1 {{candidate template ignored: disabled by 'enable_if'}}
+ // expected-note-re@future:* 1 {{candidate template ignored: {{(disabled by 'enable_if')|(requirement '.*' was not satisfied)}}}}
}
diff --git a/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp b/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp
index 253515e3db3c..f2cf9f2d4187 100644
--- a/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp
+++ b/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp
@@ -29,11 +29,12 @@ struct A
int main()
{
+ globalMemCounter.reset();
std::allocator<A> a;
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(A_constructed == 0);
globalMemCounter.last_new_size = 0;
- A* ap = a.allocate(3);
+ A* volatile ap = a.allocate(3);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int)));
assert(A_constructed == 0);
@@ -42,7 +43,7 @@ int main()
assert(A_constructed == 0);
globalMemCounter.last_new_size = 0;
- A* ap2 = a.allocate(3, (const void*)5);
+ A* volatile ap2 = a.allocate(3, (const void*)5);
assert(globalMemCounter.checkOutstandingNewEq(1));
assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int)));
assert(A_constructed == 0);
diff --git a/test/std/utilities/optional/optional.object/optional.object.assign/move.pass.cpp b/test/std/utilities/optional/optional.object/optional.object.assign/move.pass.cpp
index 3ba261b52464..ed8b433da693 100644
--- a/test/std/utilities/optional/optional.object/optional.object.assign/move.pass.cpp
+++ b/test/std/utilities/optional/optional.object/optional.object.assign/move.pass.cpp
@@ -147,27 +147,27 @@ int main()
}
{
struct ThrowsMove {
- ThrowsMove() noexcept {}
- ThrowsMove(ThrowsMove const&) noexcept {}
- ThrowsMove(ThrowsMove &&) noexcept(false) {}
- ThrowsMove& operator=(ThrowsMove const&) noexcept { return *this; }
- ThrowsMove& operator=(ThrowsMove &&) noexcept { return *this; }
+ ThrowsMove() noexcept {}
+ ThrowsMove(ThrowsMove const&) noexcept {}
+ ThrowsMove(ThrowsMove &&) noexcept(false) {}
+ ThrowsMove& operator=(ThrowsMove const&) noexcept { return *this; }
+ ThrowsMove& operator=(ThrowsMove &&) noexcept { return *this; }
};
static_assert(!std::is_nothrow_move_assignable<optional<ThrowsMove>>::value, "");
struct ThrowsMoveAssign {
- ThrowsMoveAssign() noexcept {}
- ThrowsMoveAssign(ThrowsMoveAssign const&) noexcept {}
- ThrowsMoveAssign(ThrowsMoveAssign &&) noexcept {}
- ThrowsMoveAssign& operator=(ThrowsMoveAssign const&) noexcept { return *this; }
- ThrowsMoveAssign& operator=(ThrowsMoveAssign &&) noexcept(false) { return *this; }
+ ThrowsMoveAssign() noexcept {}
+ ThrowsMoveAssign(ThrowsMoveAssign const&) noexcept {}
+ ThrowsMoveAssign(ThrowsMoveAssign &&) noexcept {}
+ ThrowsMoveAssign& operator=(ThrowsMoveAssign const&) noexcept { return *this; }
+ ThrowsMoveAssign& operator=(ThrowsMoveAssign &&) noexcept(false) { return *this; }
};
static_assert(!std::is_nothrow_move_assignable<optional<ThrowsMoveAssign>>::value, "");
struct NoThrowMove {
- NoThrowMove() noexcept(false) {}
- NoThrowMove(NoThrowMove const&) noexcept(false) {}
- NoThrowMove(NoThrowMove &&) noexcept {}
- NoThrowMove& operator=(NoThrowMove const&) noexcept { return *this; }
- NoThrowMove& operator=(NoThrowMove&&) noexcept { return *this; }
+ NoThrowMove() noexcept(false) {}
+ NoThrowMove(NoThrowMove const&) noexcept(false) {}
+ NoThrowMove(NoThrowMove &&) noexcept {}
+ NoThrowMove& operator=(NoThrowMove const&) noexcept { return *this; }
+ NoThrowMove& operator=(NoThrowMove&&) noexcept { return *this; }
};
static_assert(std::is_nothrow_move_assignable<optional<NoThrowMove>>::value, "");
}
diff --git a/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp b/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp
index 6b4283a2854b..0f1fabd0cebb 100644
--- a/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp
+++ b/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp
@@ -45,10 +45,10 @@ constexpr bool constexpr_test(InitArgs&&... args)
void test_throwing_ctor() {
#ifndef TEST_HAS_NO_EXCEPTIONS
struct Z {
- Z() : count(0) {}
- Z(Z const& o) : count(o.count + 1)
- { if (count == 2) throw 6; }
- int count;
+ Z() : count(0) {}
+ Z(Z const& o) : count(o.count + 1)
+ { if (count == 2) throw 6; }
+ int count;
};
const Z z;
const optional<Z> rhs(z);
diff --git a/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp b/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp
index 55c2156300fb..e73f3747c435 100644
--- a/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp
+++ b/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp
@@ -55,10 +55,10 @@ constexpr bool constexpr_test(InitArgs&&... args)
void test_throwing_ctor() {
#ifndef TEST_HAS_NO_EXCEPTIONS
struct Z {
- Z() : count(0) {}
- Z(Z&& o) : count(o.count + 1)
- { if (count == 2) throw 6; }
- int count;
+ Z() : count(0) {}
+ Z(Z&& o) : count(o.count + 1)
+ { if (count == 2) throw 6; }
+ int count;
};
Z z;
optional<Z> rhs(std::move(z));
diff --git a/test/std/utilities/optional/optional.object/special_member_gen.pass.cpp b/test/std/utilities/optional/optional.object/special_member_gen.pass.cpp
index fdd0f154f0e5..0b9b6e717c3a 100644
--- a/test/std/utilities/optional/optional.object/special_member_gen.pass.cpp
+++ b/test/std/utilities/optional/optional.object/special_member_gen.pass.cpp
@@ -33,10 +33,38 @@ struct SpecialMemberTest {
"optional<T> is copy assignable if and only if T is both copy "
"constructible and copy assignable.");
static_assert(std::is_move_assignable_v<O> ==
- ((std::is_copy_constructible_v<T> && std::is_copy_assignable_v<T>) ||
- (std::is_move_constructible_v<T> && std::is_move_assignable_v<T>)),
- "optional<T> is move assignable if and only if T is both move assignable and "
- "move constructible, or both copy constructible and copy assignable.");
+ ((std::is_move_constructible_v<T> && std::is_move_assignable_v<T>) ||
+ (std::is_copy_constructible_v<T> && std::is_copy_assignable_v<T>)),
+ "optional<T> is move assignable if and only if T is both move constructible and "
+ "move assignable, or both copy constructible and copy assignable.");
+
+ // The following tests are for not-yet-standardized behavior (P0602):
+ static_assert(std::is_trivially_destructible_v<O> ==
+ std::is_trivially_destructible_v<T>,
+ "optional<T> is trivially destructible if and only if T is.");
+ static_assert(std::is_trivially_copy_constructible_v<O> ==
+ std::is_trivially_copy_constructible_v<T>,
+ "optional<T> is trivially copy constructible if and only if T is.");
+ static_assert(std::is_trivially_move_constructible_v<O> ==
+ std::is_trivially_move_constructible_v<T> ||
+ (!std::is_move_constructible_v<T> && std::is_trivially_copy_constructible_v<T>),
+ "optional<T> is trivially move constructible if T is trivially move constructible, "
+ "or if T is trivially copy constructible and is not move constructible.");
+ static_assert(std::is_trivially_copy_assignable_v<O> ==
+ (std::is_trivially_destructible_v<T> &&
+ std::is_trivially_copy_constructible_v<T> &&
+ std::is_trivially_copy_assignable_v<T>),
+ "optional<T> is trivially copy assignable if and only if T is trivially destructible, "
+ "trivially copy constructible, and trivially copy assignable.");
+ static_assert(std::is_trivially_move_assignable_v<O> ==
+ (std::is_trivially_destructible_v<T> &&
+ ((std::is_trivially_move_constructible_v<T> && std::is_trivially_move_assignable_v<T>) ||
+ ((!std::is_move_constructible_v<T> || !std::is_move_assignable_v<T>) &&
+ std::is_trivially_copy_constructible_v<T> && std::is_trivially_copy_assignable_v<T>))),
+ "optional<T> is trivially move assignable if T is trivially destructible, and either "
+ "(1) trivially move constructible and trivially move assignable, or "
+ "(2) not move constructible or not move assignable, and "
+ "trivially copy constructible and trivially copy assignable.");
};
template <class ...Args> static void sink(Args&&...) {}