[libc++][test] Suppress MSVC warnings in std::expected tests
authorCasey Carter <Casey@Carter.net>
Fri, 6 Jan 2023 03:28:21 +0000 (19:28 -0800)
committerCasey Carter <Casey@Carter.net>
Fri, 6 Jan 2023 18:02:25 +0000 (10:02 -0800)
* 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

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

index 9a033ea..9295255 100644 (file)
@@ -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;
index ed705d3..5a78e41 100644 (file)
@@ -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;
index 87d7448..718c307 100644 (file)
@@ -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);
index b79b507..fa05a13 100644 (file)
@@ -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;
 }
index cdf32e6..0a857c7 100644 (file)
@@ -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;