[libcxx][test] Silence nodiscard warnings for std::expected by StephanTLavavej · Pull Request #119174 · llvm/llvm-project (original) (raw)

@llvm/pr-subscribers-libcxx

Author: Stephan T. Lavavej (StephanTLavavej)

Changes

I'm exploring marking microsoft/STL's std::expected as [[nodiscard]], which affects all functions returning std::expected, including its own monadic member functions.

As usual, libc++'s test suite contains calls to these member functions to make sure they compile, but it's discarding the returns. I'm adding (void) casts to silence the [[nodiscard]] warnings without altering what the test is covering.


Full diff: https://github.com/llvm/llvm-project/pull/119174.diff

4 Files Affected:

diff --git a/libcxx/test/std/utilities/expected/expected.expected/monadic/and_then.pass.cpp b/libcxx/test/std/utilities/expected/expected.expected/monadic/and_then.pass.cpp index 293c2d39d4a325..3ac58b34eff8c6 100644 --- a/libcxx/test/std/utilities/expected/expected.expected/monadic/and_then.pass.cpp +++ b/libcxx/test/std/utilities/expected/expected.expected/monadic/and_then.pass.cpp @@ -263,8 +263,8 @@ constexpr void test_val_types() { constexpr void test_sfinae() { std::expected<NonConst, int> e(std::unexpected(2)); auto l = [](auto&& x) { return x.non_const(); };

constexpr void test_move_only_error_type() { @@ -272,14 +272,14 @@ constexpr void test_move_only_error_type() { { std::expected<int, MoveOnlyErrorType> e; auto l = { return std::expected<int, MoveOnlyErrorType>{}; };

}

// Test const&& { const std::expected<int, MoveOnlyErrorType> e; auto l = [](const int) { return std::expected<int, MoveOnlyErrorType>{}; };

} }

@@ -296,10 +296,10 @@ constexpr bool test() { return std::expected<int, int>(); };

} diff --git a/libcxx/test/std/utilities/expected/expected.expected/monadic/or_else.pass.cpp b/libcxx/test/std/utilities/expected/expected.expected/monadic/or_else.pass.cpp index b472a2756be9f9..2587ca60a8efd2 100644 --- a/libcxx/test/std/utilities/expected/expected.expected/monadic/or_else.pass.cpp +++ b/libcxx/test/std/utilities/expected/expected.expected/monadic/or_else.pass.cpp @@ -178,8 +178,8 @@ struct NonConst { constexpr void test_sfinae() { std::expected<int, NonConst> e{1}; auto l = [](auto&& x) { return x.non_const(); };

constexpr void test_move_only_error_type() { @@ -187,28 +187,28 @@ constexpr void test_move_only_error_type() { { std::expected<int, MoveOnlyErrorType> e; auto l = { return std::expected<int, int>{}; };

@@ -225,10 +225,10 @@ constexpr bool test() { return std::expected<int, int>(); };

diff --git a/libcxx/test/std/utilities/expected/expected.expected/monadic/transform.pass.cpp b/libcxx/test/std/utilities/expected/expected.expected/monadic/transform.pass.cpp index 4fb21374aebe31..d7718205113d0b 100644 --- a/libcxx/test/std/utilities/expected/expected.expected/monadic/transform.pass.cpp +++ b/libcxx/test/std/utilities/expected/expected.expected/monadic/transform.pass.cpp @@ -187,13 +187,13 @@ constexpr void test_val_types() { constexpr void test_take_val_return_void() { std::expected<int, int> e(1); int val = 0;

@@ -237,10 +237,10 @@ constexpr void test_sfinae() { return std::expected<int, int>(); };

constexpr void test_move_only_error_type() { @@ -248,14 +248,14 @@ constexpr void test_move_only_error_type() { { std::expected<int, MoveOnlyErrorType> e; auto l = { return 0; };

diff --git a/libcxx/test/std/utilities/expected/expected.expected/monadic/transform_error.pass.cpp b/libcxx/test/std/utilities/expected/expected.expected/monadic/transform_error.pass.cpp index d35788d9fef25e..a19e17b01f6a94 100644 --- a/libcxx/test/std/utilities/expected/expected.expected/monadic/transform_error.pass.cpp +++ b/libcxx/test/std/utilities/expected/expected.expected/monadic/transform_error.pass.cpp @@ -197,8 +197,8 @@ constexpr void test_direct_non_list_init() { constexpr void test_sfinae() { std::expected<int, NonConst> e(2); auto l = [](auto&& x) { return x.non_const(); };

@@ -208,10 +208,10 @@ constexpr void test_sfinae() { return 0; };

constexpr void test_move_only_error_type() { @@ -219,28 +219,28 @@ constexpr void test_move_only_error_type() { { std::expected<int, MoveOnlyErrorType> e; auto l = { return 0; };