[libcxx-commits] [libcxx] bdf7da2 - [libc++][test] Suppress MSVC warnings in std::expected tests
Casey Carter via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jan 6 10:02:44 PST 2023
Author: Casey Carter
Date: 2023-01-06T10:02:25-08:00
New Revision: bdf7da280f624c53e6184d0410041220a9b405a7
URL: https://github.com/llvm/llvm-project/commit/bdf7da280f624c53e6184d0410041220a9b405a7
DIFF: https://github.com/llvm/llvm-project/commit/bdf7da280f624c53e6184d0410041220a9b405a7.diff
LOG: [libc++][test] Suppress MSVC warnings in std::expected tests
* initializing `short`s with `short`s instead of `int`s to avoid narrowing warnings
* Explicitly discard the result of `value` calls to avoid `[[nodiscard]]` warnings
Drive-by: `testException` from `value` test is duplicated in `value_or` test; remove the duplicate.
Differential Review: https://reviews.llvm.org/D141108
Added:
Modified:
libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.inplace.pass.cpp
libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.unexpect.pass.cpp
libcxx/test/std/utilities/expected/expected.expected/observers/value.pass.cpp
libcxx/test/std/utilities/expected/expected.expected/observers/value_or.pass.cpp
libcxx/test/std/utilities/expected/expected.void/ctor/ctor.unexpect.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.inplace.pass.cpp b/libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.inplace.pass.cpp
index 9a033eaeb7d6a..92952551711e0 100644
--- a/libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.inplace.pass.cpp
+++ b/libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.inplace.pass.cpp
@@ -101,9 +101,9 @@ constexpr bool test() {
// multi args
{
- std::expected<std::tuple<int, short, MoveOnly>, int> e(std::in_place, 1, 2, MoveOnly(3));
+ std::expected<std::tuple<int, short, MoveOnly>, int> e(std::in_place, 1, short{2}, MoveOnly(3));
assert(e.has_value());
- assert((e.value() == std::tuple<int, short, MoveOnly>(1, 2, MoveOnly(3))));
+ assert((e.value() == std::tuple<int, short, MoveOnly>(1, short{2}, MoveOnly(3))));
}
return true;
diff --git a/libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.unexpect.pass.cpp b/libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.unexpect.pass.cpp
index ed705d35ee019..5a78e41dfcae2 100644
--- a/libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.unexpect.pass.cpp
+++ b/libcxx/test/std/utilities/expected/expected.expected/ctor/ctor.unexpect.pass.cpp
@@ -101,9 +101,9 @@ constexpr bool test() {
// multi args
{
- std::expected<int, std::tuple<int, short, MoveOnly>> e(std::unexpect, 1, 2, MoveOnly(3));
+ std::expected<int, std::tuple<int, short, MoveOnly>> e(std::unexpect, 1, short{2}, MoveOnly(3));
assert(!e.has_value());
- assert((e.error() == std::tuple<int, short, MoveOnly>(1, 2, MoveOnly(3))));
+ assert((e.error() == std::tuple<int, short, MoveOnly>(1, short{2}, MoveOnly(3))));
}
return true;
diff --git a/libcxx/test/std/utilities/expected/expected.expected/observers/value.pass.cpp b/libcxx/test/std/utilities/expected/expected.expected/observers/value.pass.cpp
index 87d74486f280e..718c307bed6da 100644
--- a/libcxx/test/std/utilities/expected/expected.expected/observers/value.pass.cpp
+++ b/libcxx/test/std/utilities/expected/expected.expected/observers/value.pass.cpp
@@ -68,7 +68,7 @@ void testException() {
{
const std::expected<int, int> e(std::unexpect, 5);
try {
- e.value();
+ (void) e.value();
assert(false);
} catch (const std::bad_expected_access<int>& ex) {
assert(ex.error() == 5);
@@ -79,7 +79,7 @@ void testException() {
{
std::expected<int, MoveOnly> e(std::unexpect, 5);
try {
- std::move(e).value();
+ (void) std::move(e).value();
assert(false);
} catch (const std::bad_expected_access<MoveOnly>& ex) {
assert(ex.error() == 5);
diff --git a/libcxx/test/std/utilities/expected/expected.expected/observers/value_or.pass.cpp b/libcxx/test/std/utilities/expected/expected.expected/observers/value_or.pass.cpp
index b79b507e52550..fa05a136e2f86 100644
--- a/libcxx/test/std/utilities/expected/expected.expected/observers/value_or.pass.cpp
+++ b/libcxx/test/std/utilities/expected/expected.expected/observers/value_or.pass.cpp
@@ -51,37 +51,8 @@ constexpr bool test() {
return true;
}
-void testException() {
-#ifndef TEST_HAS_NO_EXCEPTIONS
-
- // int
- {
- const std::expected<int, int> e(std::unexpect, 5);
- try {
- e.value();
- assert(false);
- } catch (const std::bad_expected_access<int>& ex) {
- assert(ex.error() == 5);
- }
- }
-
- // MoveOnly
- {
- std::expected<int, MoveOnly> e(std::unexpect, 5);
- try {
- std::move(e).value();
- assert(false);
- } catch (const std::bad_expected_access<MoveOnly>& ex) {
- assert(ex.error() == 5);
- }
- }
-
-#endif // TEST_HAS_NO_EXCEPTIONS
-}
-
int main(int, char**) {
test();
static_assert(test());
- testException();
return 0;
}
diff --git a/libcxx/test/std/utilities/expected/expected.void/ctor/ctor.unexpect.pass.cpp b/libcxx/test/std/utilities/expected/expected.void/ctor/ctor.unexpect.pass.cpp
index cdf32e68ceac3..0a857c77d9c7a 100644
--- a/libcxx/test/std/utilities/expected/expected.void/ctor/ctor.unexpect.pass.cpp
+++ b/libcxx/test/std/utilities/expected/expected.void/ctor/ctor.unexpect.pass.cpp
@@ -101,9 +101,9 @@ constexpr bool test() {
// multi args
{
- std::expected<void, std::tuple<int, short, MoveOnly>> e(std::unexpect, 1, 2, MoveOnly(3));
+ std::expected<void, std::tuple<int, short, MoveOnly>> e(std::unexpect, 1, short{2}, MoveOnly(3));
assert(!e.has_value());
- assert((e.error() == std::tuple<int, short, MoveOnly>(1, 2, MoveOnly(3))));
+ assert((e.error() == std::tuple<int, short, MoveOnly>(1, short{2}, MoveOnly(3))));
}
return true;
More information about the libcxx-commits
mailing list