[libcxx-commits] [libcxx] [libc++][test] Fix simple warnings (PR #74186)
Stephan T. Lavavej via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Dec 4 17:41:04 PST 2023
https://github.com/StephanTLavavej updated https://github.com/llvm/llvm-project/pull/74186
>From b3c28e7797147c9ded10437b2f79a4eadd7ef64f Mon Sep 17 00:00:00 2001
From: "Stephan T. Lavavej" <stl at nuwen.net>
Date: Wed, 29 Nov 2023 21:59:33 -0800
Subject: [PATCH 1/7] Avoid mixing preprocessor and runtime tests.
move_backward.pass.cpp(95): warning C4127: conditional expression is constant
---
.../alg.modifying.operations/alg.move/move.pass.cpp | 7 ++++++-
.../alg.move/move_backward.pass.cpp | 7 ++++++-
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp
index ce5cf0560fc81..e6019c477f93e 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp
@@ -94,8 +94,13 @@ struct Test1OutIters {
TEST_CONSTEXPR_CXX20 bool test() {
types::for_each(types::cpp17_input_iterator_list<int*>(), TestOutIters());
- if (TEST_STD_VER >= 23 || !TEST_IS_CONSTANT_EVALUATED)
+
+#if TEST_STD_VER < 23
+ if (!TEST_IS_CONSTANT_EVALUATED)
+#endif
+ {
types::for_each(types::cpp17_input_iterator_list<std::unique_ptr<int>*>(), Test1OutIters());
+ }
{ // Make sure that padding bits aren't copied
Derived src(1, 2, 3);
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp
index 2ed4d37b9dbe6..dcee48244288b 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp
@@ -92,8 +92,13 @@ struct Test1OutIters {
TEST_CONSTEXPR_CXX20 bool test() {
types::for_each(types::bidirectional_iterator_list<int*>(), TestOutIters());
- if (TEST_STD_VER >= 23 || !TEST_IS_CONSTANT_EVALUATED)
+
+#if TEST_STD_VER < 23
+ if (!TEST_IS_CONSTANT_EVALUATED)
+#endif
+ {
types::for_each(types::bidirectional_iterator_list<std::unique_ptr<int>*>(), Test1OutIters());
+ }
{ // Make sure that padding bits aren't copied
Derived src(1, 2, 3);
>From 390d7bcee42da10f8f90e2a3903bef52712927c6 Mon Sep 17 00:00:00 2001
From: "Stephan T. Lavavej" <stl at nuwen.net>
Date: Thu, 30 Nov 2023 12:46:42 -0800
Subject: [PATCH 2/7] Add void-casts to fix -Wunused-variable warnings.
---
libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp | 1 +
.../thread.mutex/thread.lock/thread.lock.scoped/mutex.pass.cpp | 1 +
.../thread.shared_mutex.class/default.pass.cpp | 1 +
3 files changed, 3 insertions(+)
diff --git a/libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp b/libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp
index a2d46ab1b94c7..796ab41716dd5 100644
--- a/libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp
+++ b/libcxx/test/std/numerics/rand/rand.device/ctor.pass.cpp
@@ -61,6 +61,7 @@ void check_random_device_invalid(const std::string &token) {
int main(int, char**) {
{
std::random_device r;
+ (void)r;
}
// Check the validity of various tokens
{
diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.scoped/mutex.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.scoped/mutex.pass.cpp
index 48a96f90254e3..f953fa4f8d6df 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.scoped/mutex.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.scoped/mutex.pass.cpp
@@ -66,6 +66,7 @@ int main(int, char**)
{
using LG = std::scoped_lock<>;
LG lg;
+ (void)lg;
}
{
using LG = std::scoped_lock<TestMutex>;
diff --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/default.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/default.pass.cpp
index 91320a52b62ae..6b4da89c4f2d4 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/default.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/default.pass.cpp
@@ -22,6 +22,7 @@
int main(int, char**)
{
std::shared_mutex m;
+ (void)m;
return 0;
}
>From 77492aab43b20616fb2043fe544fc99af6bd99a1 Mon Sep 17 00:00:00 2001
From: "Stephan T. Lavavej" <stl at nuwen.net>
Date: Thu, 30 Nov 2023 22:49:44 -0800
Subject: [PATCH 3/7] Avoid sign/truncation warnings in
ConvertibleToIntegral.h.
Examples:
libcxx\test\std\containers\views\mdspan\layout_stride\../ConvertibleToIntegral.h(19): warning C4242: 'return': conversion from 'const int' to 'unsigned char', possible loss of data
libcxx\test\std\containers\views\mdspan\layout_stride\../ConvertibleToIntegral.h(20): warning C4242: 'return': conversion from 'const int' to 'signed char', possible loss of data
libcxx\test\std\containers\views\mdspan\layout_stride\../ConvertibleToIntegral.h(32): warning C4242: 'return': conversion from 'int' to 'char', possible loss of data
---
.../std/containers/views/mdspan/ConvertibleToIntegral.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libcxx/test/std/containers/views/mdspan/ConvertibleToIntegral.h b/libcxx/test/std/containers/views/mdspan/ConvertibleToIntegral.h
index 470f5d8e72464..0ca5c330a390e 100644
--- a/libcxx/test/std/containers/views/mdspan/ConvertibleToIntegral.h
+++ b/libcxx/test/std/containers/views/mdspan/ConvertibleToIntegral.h
@@ -16,8 +16,8 @@ struct IntType {
constexpr bool operator==(const IntType& rhs) const { return val == rhs.val; }
constexpr operator int() const noexcept { return val; }
- constexpr operator unsigned char() const { return val; }
- constexpr operator signed char() const noexcept { return val; }
+ constexpr operator unsigned char() const { return static_cast<unsigned char>(val); }
+ constexpr operator signed char() const noexcept { return static_cast<signed char>(val); }
};
// only non-const convertible
@@ -28,8 +28,8 @@ struct IntTypeNC {
constexpr bool operator==(const IntType& rhs) const { return val == rhs.val; }
constexpr operator int() noexcept { return val; }
- constexpr operator unsigned() { return val; }
- constexpr operator char() noexcept { return val; }
+ constexpr operator unsigned() { return static_cast<unsigned>(val); }
+ constexpr operator char() noexcept { return static_cast<char>(val); }
};
// weird configurability of convertibility to int
>From 4b2a6a2d97cb3f5d0a48669cc69974b35396de77 Mon Sep 17 00:00:00 2001
From: "Stephan T. Lavavej" <stl at nuwen.net>
Date: Fri, 1 Dec 2023 23:29:08 -0800
Subject: [PATCH 4/7] Apply clang-format from CI.
---
.../thread.shared_mutex.class/default.pass.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/default.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/default.pass.cpp
index 6b4da89c4f2d4..5504645bb31f9 100644
--- a/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/default.pass.cpp
+++ b/libcxx/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/default.pass.cpp
@@ -24,5 +24,5 @@ int main(int, char**)
std::shared_mutex m;
(void)m;
- return 0;
+ return 0;
}
>From 8edd766b074a2f7de8d5c1138e3e5ed332b2a0e7 Mon Sep 17 00:00:00 2001
From: "Stephan T. Lavavej" <stl at nuwen.net>
Date: Mon, 4 Dec 2023 16:35:29 -0800
Subject: [PATCH 5/7] Revert "Avoid mixing preprocessor and runtime tests."
This reverts commit b3c28e7797147c9ded10437b2f79a4eadd7ef64f.
---
.../alg.modifying.operations/alg.move/move.pass.cpp | 7 +------
.../alg.move/move_backward.pass.cpp | 7 +------
2 files changed, 2 insertions(+), 12 deletions(-)
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp
index e6019c477f93e..ce5cf0560fc81 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp
@@ -94,13 +94,8 @@ struct Test1OutIters {
TEST_CONSTEXPR_CXX20 bool test() {
types::for_each(types::cpp17_input_iterator_list<int*>(), TestOutIters());
-
-#if TEST_STD_VER < 23
- if (!TEST_IS_CONSTANT_EVALUATED)
-#endif
- {
+ if (TEST_STD_VER >= 23 || !TEST_IS_CONSTANT_EVALUATED)
types::for_each(types::cpp17_input_iterator_list<std::unique_ptr<int>*>(), Test1OutIters());
- }
{ // Make sure that padding bits aren't copied
Derived src(1, 2, 3);
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp
index dcee48244288b..2ed4d37b9dbe6 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp
@@ -92,13 +92,8 @@ struct Test1OutIters {
TEST_CONSTEXPR_CXX20 bool test() {
types::for_each(types::bidirectional_iterator_list<int*>(), TestOutIters());
-
-#if TEST_STD_VER < 23
- if (!TEST_IS_CONSTANT_EVALUATED)
-#endif
- {
+ if (TEST_STD_VER >= 23 || !TEST_IS_CONSTANT_EVALUATED)
types::for_each(types::bidirectional_iterator_list<std::unique_ptr<int>*>(), Test1OutIters());
- }
{ // Make sure that padding bits aren't copied
Derived src(1, 2, 3);
>From 5fd8a6e068467f4ff46b2e36a0ae249a9267f2b8 Mon Sep 17 00:00:00 2001
From: "Stephan T. Lavavej" <stl at nuwen.net>
Date: Mon, 4 Dec 2023 16:41:31 -0800
Subject: [PATCH 6/7] `!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20` is
always true.
We don't need to keep `{ ... }` for artificial scopes anywhere.
---
.../alg.nonmodifying/alg.count/count.pass.cpp | 16 +++++++---------
.../string.view.comparison/equal.pass.cpp | 12 ++++--------
.../string.view.comparison/greater.pass.cpp | 12 ++++--------
.../greater_equal.pass.cpp | 12 ++++--------
.../string.view.comparison/less.pass.cpp | 12 ++++--------
.../string.view.comparison/less_equal.pass.cpp | 12 ++++--------
.../string.view.comparison/not_equal.pass.cpp | 12 ++++--------
7 files changed, 31 insertions(+), 57 deletions(-)
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.count/count.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.count/count.pass.cpp
index cc832febdba75..ca31c88ded614 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.count/count.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.count/count.pass.cpp
@@ -38,15 +38,13 @@ struct Test {
TEST_CONSTEXPR_CXX20 bool test() {
types::for_each(types::cpp17_input_iterator_list<const int*>(), Test());
- if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) {
- std::vector<bool> vec(256 + 64);
- for (ptrdiff_t i = 0; i != 256; ++i) {
- for (size_t offset = 0; offset != 64; ++offset) {
- std::fill(vec.begin(), vec.end(), false);
- std::fill(vec.begin() + offset, vec.begin() + i + offset, true);
- assert(std::count(vec.begin() + offset, vec.begin() + offset + 256, true) == i);
- assert(std::count(vec.begin() + offset, vec.begin() + offset + 256, false) == 256 - i);
- }
+ std::vector<bool> vec(256 + 64);
+ for (ptrdiff_t i = 0; i != 256; ++i) {
+ for (size_t offset = 0; offset != 64; ++offset) {
+ std::fill(vec.begin(), vec.end(), false);
+ std::fill(vec.begin() + offset, vec.begin() + i + offset, true);
+ assert(std::count(vec.begin() + offset, vec.begin() + offset + 256, true) == i);
+ assert(std::count(vec.begin() + offset, vec.begin() + offset + 256, false) == 256 - i);
}
}
diff --git a/libcxx/test/std/strings/string.view/string.view.comparison/equal.pass.cpp b/libcxx/test/std/strings/string.view/string.view.comparison/equal.pass.cpp
index 4f00bd7f6edf1..616820338e831 100644
--- a/libcxx/test/std/strings/string.view/string.view.comparison/equal.pass.cpp
+++ b/libcxx/test/std/strings/string.view/string.view.comparison/equal.pass.cpp
@@ -51,10 +51,8 @@ TEST_CONSTEXPR_CXX14 bool test() {
assert((ConvertibleTo<SV>(v[i]) == v[j]) == expected);
assert((v[i] == ConvertibleTo<SV>(v[j])) == expected);
- if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) {
- assert((std::basic_string<CharT, Traits>(v[i]) == v[j]) == expected);
- assert((v[i] == std::basic_string<CharT, Traits>(v[j])) == expected);
- }
+ assert((std::basic_string<CharT, Traits>(v[i]) == v[j]) == expected);
+ assert((v[i] == std::basic_string<CharT, Traits>(v[j])) == expected);
}
}
@@ -72,10 +70,8 @@ TEST_CONSTEXPR_CXX14 bool test() {
assert((abc.data() == abc0def) == false);
assert((abc0def == abc.data()) == false);
- if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) {
- assert((std::basic_string<CharT, Traits>(abc) == abc0def) == false);
- assert((abc0def == std::basic_string<CharT, Traits>(abc)) == false);
- }
+ assert((std::basic_string<CharT, Traits>(abc) == abc0def) == false);
+ assert((abc0def == std::basic_string<CharT, Traits>(abc)) == false);
return true;
}
diff --git a/libcxx/test/std/strings/string.view/string.view.comparison/greater.pass.cpp b/libcxx/test/std/strings/string.view/string.view.comparison/greater.pass.cpp
index b965c155ec51b..6aabd6a00a133 100644
--- a/libcxx/test/std/strings/string.view/string.view.comparison/greater.pass.cpp
+++ b/libcxx/test/std/strings/string.view/string.view.comparison/greater.pass.cpp
@@ -51,10 +51,8 @@ TEST_CONSTEXPR_CXX14 bool test() {
assert((ConvertibleTo<SV>(v[i]) > v[j]) == expected);
assert((v[i] > ConvertibleTo<SV>(v[j])) == expected);
- if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) {
- assert((std::basic_string<CharT, Traits>(v[i]) > v[j]) == expected);
- assert((v[i] > std::basic_string<CharT, Traits>(v[j])) == expected);
- }
+ assert((std::basic_string<CharT, Traits>(v[i]) > v[j]) == expected);
+ assert((v[i] > std::basic_string<CharT, Traits>(v[j])) == expected);
}
}
@@ -72,10 +70,8 @@ TEST_CONSTEXPR_CXX14 bool test() {
assert((abc.data() > abc0def) == false);
assert((abc0def > abc.data()) == true);
- if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) {
- assert((std::basic_string<CharT, Traits>(abc) > abc0def) == false);
- assert((abc0def > std::basic_string<CharT, Traits>(abc)) == true);
- }
+ assert((std::basic_string<CharT, Traits>(abc) > abc0def) == false);
+ assert((abc0def > std::basic_string<CharT, Traits>(abc)) == true);
return true;
}
diff --git a/libcxx/test/std/strings/string.view/string.view.comparison/greater_equal.pass.cpp b/libcxx/test/std/strings/string.view/string.view.comparison/greater_equal.pass.cpp
index 435e7db773199..39ca29ba7f8d8 100644
--- a/libcxx/test/std/strings/string.view/string.view.comparison/greater_equal.pass.cpp
+++ b/libcxx/test/std/strings/string.view/string.view.comparison/greater_equal.pass.cpp
@@ -51,10 +51,8 @@ TEST_CONSTEXPR_CXX14 bool test() {
assert((ConvertibleTo<SV>(v[i]) >= v[j]) == expected);
assert((v[i] >= ConvertibleTo<SV>(v[j])) == expected);
- if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) {
- assert((std::basic_string<CharT, Traits>(v[i]) >= v[j]) == expected);
- assert((v[i] >= std::basic_string<CharT, Traits>(v[j])) == expected);
- }
+ assert((std::basic_string<CharT, Traits>(v[i]) >= v[j]) == expected);
+ assert((v[i] >= std::basic_string<CharT, Traits>(v[j])) == expected);
}
}
@@ -72,10 +70,8 @@ TEST_CONSTEXPR_CXX14 bool test() {
assert((abc.data() >= abc0def) == false);
assert((abc0def >= abc.data()) == true);
- if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) {
- assert((std::basic_string<CharT, Traits>(abc) >= abc0def) == false);
- assert((abc0def >= std::basic_string<CharT, Traits>(abc)) == true);
- }
+ assert((std::basic_string<CharT, Traits>(abc) >= abc0def) == false);
+ assert((abc0def >= std::basic_string<CharT, Traits>(abc)) == true);
return true;
}
diff --git a/libcxx/test/std/strings/string.view/string.view.comparison/less.pass.cpp b/libcxx/test/std/strings/string.view/string.view.comparison/less.pass.cpp
index 7461b05ce3085..ea5b96bced519 100644
--- a/libcxx/test/std/strings/string.view/string.view.comparison/less.pass.cpp
+++ b/libcxx/test/std/strings/string.view/string.view.comparison/less.pass.cpp
@@ -51,10 +51,8 @@ TEST_CONSTEXPR_CXX14 bool test() {
assert((ConvertibleTo<SV>(v[i]) < v[j]) == expected);
assert((v[i] < ConvertibleTo<SV>(v[j])) == expected);
- if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) {
- assert((std::basic_string<CharT, Traits>(v[i]) < v[j]) == expected);
- assert((v[i] < std::basic_string<CharT, Traits>(v[j])) == expected);
- }
+ assert((std::basic_string<CharT, Traits>(v[i]) < v[j]) == expected);
+ assert((v[i] < std::basic_string<CharT, Traits>(v[j])) == expected);
}
}
@@ -72,10 +70,8 @@ TEST_CONSTEXPR_CXX14 bool test() {
assert((abc.data() < abc0def) == true);
assert((abc0def < abc.data()) == false);
- if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) {
- assert((std::basic_string<CharT, Traits>(abc) < abc0def) == true);
- assert((abc0def < std::basic_string<CharT, Traits>(abc)) == false);
- }
+ assert((std::basic_string<CharT, Traits>(abc) < abc0def) == true);
+ assert((abc0def < std::basic_string<CharT, Traits>(abc)) == false);
return true;
}
diff --git a/libcxx/test/std/strings/string.view/string.view.comparison/less_equal.pass.cpp b/libcxx/test/std/strings/string.view/string.view.comparison/less_equal.pass.cpp
index 3192db0dc7d7d..21af73dbf9938 100644
--- a/libcxx/test/std/strings/string.view/string.view.comparison/less_equal.pass.cpp
+++ b/libcxx/test/std/strings/string.view/string.view.comparison/less_equal.pass.cpp
@@ -51,10 +51,8 @@ TEST_CONSTEXPR_CXX14 bool test() {
assert((ConvertibleTo<SV>(v[i]) <= v[j]) == expected);
assert((v[i] <= ConvertibleTo<SV>(v[j])) == expected);
- if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) {
- assert((std::basic_string<CharT, Traits>(v[i]) <= v[j]) == expected);
- assert((v[i] <= std::basic_string<CharT, Traits>(v[j])) == expected);
- }
+ assert((std::basic_string<CharT, Traits>(v[i]) <= v[j]) == expected);
+ assert((v[i] <= std::basic_string<CharT, Traits>(v[j])) == expected);
}
}
@@ -72,10 +70,8 @@ TEST_CONSTEXPR_CXX14 bool test() {
assert((abc.data() <= abc0def) == true);
assert((abc0def <= abc.data()) == false);
- if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) {
- assert((std::basic_string<CharT, Traits>(abc) <= abc0def) == true);
- assert((abc0def <= std::basic_string<CharT, Traits>(abc)) == false);
- }
+ assert((std::basic_string<CharT, Traits>(abc) <= abc0def) == true);
+ assert((abc0def <= std::basic_string<CharT, Traits>(abc)) == false);
return true;
}
diff --git a/libcxx/test/std/strings/string.view/string.view.comparison/not_equal.pass.cpp b/libcxx/test/std/strings/string.view/string.view.comparison/not_equal.pass.cpp
index 0082a56839331..70048177df0f1 100644
--- a/libcxx/test/std/strings/string.view/string.view.comparison/not_equal.pass.cpp
+++ b/libcxx/test/std/strings/string.view/string.view.comparison/not_equal.pass.cpp
@@ -51,10 +51,8 @@ TEST_CONSTEXPR_CXX14 bool test() {
assert((ConvertibleTo<SV>(v[i]) != v[j]) == expected);
assert((v[i] != ConvertibleTo<SV>(v[j])) == expected);
- if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) {
- assert((std::basic_string<CharT, Traits>(v[i]) != v[j]) == expected);
- assert((v[i] != std::basic_string<CharT, Traits>(v[j])) == expected);
- }
+ assert((std::basic_string<CharT, Traits>(v[i]) != v[j]) == expected);
+ assert((v[i] != std::basic_string<CharT, Traits>(v[j])) == expected);
}
}
@@ -72,10 +70,8 @@ TEST_CONSTEXPR_CXX14 bool test() {
assert((abc.data() != abc0def) == true);
assert((abc0def != abc.data()) == true);
- if (!TEST_IS_CONSTANT_EVALUATED || TEST_STD_VER >= 20) {
- assert((std::basic_string<CharT, Traits>(abc) != abc0def) == true);
- assert((abc0def != std::basic_string<CharT, Traits>(abc)) == true);
- }
+ assert((std::basic_string<CharT, Traits>(abc) != abc0def) == true);
+ assert((abc0def != std::basic_string<CharT, Traits>(abc)) == true);
return true;
}
>From 8693810ab7cec59332b5f5a368379ce4735347d8 Mon Sep 17 00:00:00 2001
From: "Stephan T. Lavavej" <stl at nuwen.net>
Date: Mon, 4 Dec 2023 17:01:41 -0800
Subject: [PATCH 7/7] Add `TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED`.
---
.../alg.modifying.operations/alg.move/move.pass.cpp | 2 +-
.../alg.move/move_backward.pass.cpp | 2 +-
libcxx/test/support/test_macros.h | 8 ++++++++
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp
index ce5cf0560fc81..b1ad6873bc5e5 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp
@@ -94,7 +94,7 @@ struct Test1OutIters {
TEST_CONSTEXPR_CXX20 bool test() {
types::for_each(types::cpp17_input_iterator_list<int*>(), TestOutIters());
- if (TEST_STD_VER >= 23 || !TEST_IS_CONSTANT_EVALUATED)
+ if (TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED)
types::for_each(types::cpp17_input_iterator_list<std::unique_ptr<int>*>(), Test1OutIters());
{ // Make sure that padding bits aren't copied
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp
index 2ed4d37b9dbe6..61dea47b51071 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp
@@ -92,7 +92,7 @@ struct Test1OutIters {
TEST_CONSTEXPR_CXX20 bool test() {
types::for_each(types::bidirectional_iterator_list<int*>(), TestOutIters());
- if (TEST_STD_VER >= 23 || !TEST_IS_CONSTANT_EVALUATED)
+ if (TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED)
types::for_each(types::bidirectional_iterator_list<std::unique_ptr<int>*>(), Test1OutIters());
{ // Make sure that padding bits aren't copied
diff --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h
index f3c6d8080ff6d..c883a156d8d01 100644
--- a/libcxx/test/support/test_macros.h
+++ b/libcxx/test/support/test_macros.h
@@ -151,6 +151,14 @@
# define TEST_IS_CONSTANT_EVALUATED false
#endif
+#if TEST_STD_VER >= 23
+# define TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED true
+#elif TEST_STD_VER == 20
+# define TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED (!std::is_constant_evaluated())
+#else
+# define TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED true
+#endif
+
#if TEST_STD_VER >= 14
# define TEST_CONSTEXPR_CXX14 constexpr
#else
More information about the libcxx-commits
mailing list