[libcxx-commits] [libcxx] 5d2b8fa - [libc++][test] add vector<bool>::reference tests
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jan 31 08:47:54 PST 2022
Author: Nikolas Klauser
Date: 2022-01-31T17:46:12+01:00
New Revision: 5d2b8fa155a57cf863ec2e3e367c663431ee8c31
URL: https://github.com/llvm/llvm-project/commit/5d2b8fa155a57cf863ec2e3e367c663431ee8c31
DIFF: https://github.com/llvm/llvm-project/commit/5d2b8fa155a57cf863ec2e3e367c663431ee8c31.diff
LOG: [libc++][test] add vector<bool>::reference tests
Add test coverage for `vector<bool>::reference`
Reviewed By: Quuxplusone, ldionne, #libc
Spies: libcxx-commits
Differential Revision: https://reviews.llvm.org/D117780
Added:
libcxx/test/std/containers/sequences/vector.bool/reference/assign_bool.pass.cpp
libcxx/test/std/containers/sequences/vector.bool/reference/assign_copy.pass.cpp
libcxx/test/std/containers/sequences/vector.bool/reference/ctor_copy.pass.cpp
libcxx/test/std/containers/sequences/vector.bool/reference/flip.pass.cpp
libcxx/test/std/containers/sequences/vector.bool/reference/operator_bool.pass.cpp
libcxx/test/std/containers/sequences/vector.bool/reference/triviality.compile.pass.cpp
Modified:
Removed:
################################################################################
diff --git a/libcxx/test/std/containers/sequences/vector.bool/reference/assign_bool.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/reference/assign_bool.pass.cpp
new file mode 100644
index 0000000000000..6bad37dc1035c
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/vector.bool/reference/assign_bool.pass.cpp
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <vector>
+
+// reference& operator=(bool)
+
+#include <cassert>
+#include <vector>
+
+bool test() {
+ std::vector<bool> vec;
+ typedef std::vector<bool>::reference Ref;
+ vec.push_back(true);
+ vec.push_back(false);
+ Ref ref = vec[0];
+ const Ref cref = vec[0];
+
+ assert(ref);
+ ref = false;
+ assert(!vec[0]);
+ assert(!vec[1]);
+ ref = true;
+ assert(vec[0]);
+ assert(!vec[1]);
+
+ assert(cref);
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+
+ return 0;
+}
diff --git a/libcxx/test/std/containers/sequences/vector.bool/reference/assign_copy.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/reference/assign_copy.pass.cpp
new file mode 100644
index 0000000000000..d56342a9e9f56
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/vector.bool/reference/assign_copy.pass.cpp
@@ -0,0 +1,76 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <vector>
+
+// reference& operator=(const reference&)
+
+#include <cassert>
+#include <vector>
+
+bool test() {
+ std::vector<bool> vec;
+ typedef std::vector<bool>::reference Ref;
+ vec.push_back(true);
+ vec.push_back(false);
+ Ref ref1 = vec[0];
+ Ref ref2 = vec[1];
+ ref2 = ref1;
+ // Ref&
+ {
+ vec[0] = false;
+ vec[1] = true;
+ ref1 = ref2;
+ assert(vec[0]);
+ assert(vec[1]);
+ }
+ {
+ vec[0] = true;
+ vec[1] = false;
+ ref1 = ref2;
+ assert(!vec[0]);
+ assert(!vec[1]);
+ }
+ // Ref&&
+ {
+ vec[0] = false;
+ vec[1] = true;
+ ref1 = std::move(ref2);
+ assert(vec[0]);
+ assert(vec[1]);
+ }
+ {
+ vec[0] = true;
+ vec[1] = false;
+ ref1 = std::move(ref2);
+ assert(!vec[0]);
+ assert(!vec[1]);
+ }
+ // const Ref&
+ {
+ vec[0] = false;
+ vec[1] = true;
+ ref1 = static_cast<const Ref&>(ref2);
+ assert(vec[0]);
+ assert(vec[1]);
+ }
+ {
+ vec[0] = true;
+ vec[1] = false;
+ ref1 = static_cast<const Ref&>(ref2);
+ assert(!vec[0]);
+ assert(!vec[1]);
+ }
+ return true;
+}
+
+int main(int, char**) {
+ test();
+
+ return 0;
+}
diff --git a/libcxx/test/std/containers/sequences/vector.bool/reference/ctor_copy.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/reference/ctor_copy.pass.cpp
new file mode 100644
index 0000000000000..0348b47bc2603
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/vector.bool/reference/ctor_copy.pass.cpp
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <vector>
+
+// reference(const reference&)
+
+#include <cassert>
+#include <vector>
+
+bool test() {
+ std::vector<bool> vec;
+ typedef std::vector<bool>::reference Ref;
+ vec.push_back(true);
+ Ref ref = vec[0];
+ Ref ref2 = ref;
+ assert(ref == ref2 && ref2);
+ ref.flip();
+ assert(ref == ref2 && !ref2);
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+
+ return 0;
+}
diff --git a/libcxx/test/std/containers/sequences/vector.bool/reference/flip.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/reference/flip.pass.cpp
new file mode 100644
index 0000000000000..8890fbfbb4df0
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/vector.bool/reference/flip.pass.cpp
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <vector>
+
+// flip()
+
+#include <cassert>
+#include <vector>
+
+bool test() {
+ std::vector<bool> vec;
+ typedef std::vector<bool>::reference Ref;
+ vec.push_back(true);
+ vec.push_back(false);
+ Ref ref = vec[0];
+ assert(vec[0]);
+ assert(!vec[1]);
+ ref.flip();
+ assert(!vec[0]);
+ assert(!vec[1]);
+ ref.flip();
+ assert(vec[0]);
+ assert(!vec[1]);
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+
+ return 0;
+}
diff --git a/libcxx/test/std/containers/sequences/vector.bool/reference/operator_bool.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/reference/operator_bool.pass.cpp
new file mode 100644
index 0000000000000..8d9d616199deb
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/vector.bool/reference/operator_bool.pass.cpp
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <vector>
+
+// operator bool()
+
+#include <cassert>
+#include <type_traits>
+#include <vector>
+
+bool test() {
+ std::vector<bool> vec;
+ typedef std::vector<bool>::reference Ref;
+ static_assert(std::is_convertible<Ref, bool>::value, "");
+
+ vec.push_back(true);
+ vec.push_back(false);
+ Ref true_ref = vec[0];
+ Ref false_ref = vec[1];
+ bool b = true_ref;
+ assert(b);
+ assert(true_ref);
+ assert(!false_ref);
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+
+ return 0;
+}
diff --git a/libcxx/test/std/containers/sequences/vector.bool/reference/triviality.compile.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/reference/triviality.compile.pass.cpp
new file mode 100644
index 0000000000000..7e403ff817188
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/vector.bool/reference/triviality.compile.pass.cpp
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include <type_traits>
+#include <vector>
+
+#include "test_macros.h"
+
+using Ref = std::vector<bool>::reference;
+
+LIBCPP_STATIC_ASSERT(!std::is_trivially_constructible<Ref>::value, "");
+LIBCPP_STATIC_ASSERT(std::is_trivially_copy_constructible<Ref>::value, "");
+LIBCPP_STATIC_ASSERT(std::is_trivially_move_constructible<Ref>::value, "");
+LIBCPP_STATIC_ASSERT(!std::is_trivially_copy_assignable<Ref>::value, "");
+LIBCPP_STATIC_ASSERT(!std::is_trivially_move_assignable<Ref>::value, "");
+LIBCPP_STATIC_ASSERT(std::is_trivially_destructible<Ref>::value, "");
More information about the libcxx-commits
mailing list