-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[libc++] mark std::expected
as nodiscard
#130820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5ef0eb9
[libc++] mark `std::expected` as `nodiscard` (fix #130656)
hulxv 5943a16
[libcxx] unit test for verifing `nodiscard` for `std::expected`
hulxv 9c7a735
[libcxx] [test] improve `expected/nodiscrard.verify`
hulxv 6147e4e
[libcxx] revert the frozen header
hulxv c4b2367
[libcxx] add `[[nodiscard]]` to `expected.h`
hulxv 66e1dbc
[libcxx] [test] casting to `void` to avoid `nodiscard` warnings
hulxv a5f9e46
[libcxx] add `nodiscard` test for monadic operations
hulxv c71ba32
Merge branch 'main' into fix/expected-nodiscard
hulxv 25a3cd7
[libcxx] fix `std::expected` tests
hulxv b831af3
[libcxx] fix formatting
hulxv aec1cce
fixing tests
hulxv 65d3a83
trying to fix failing tests
hulxv a78a333
fix `nodiscard.verify.cpp`
hulxv aa6d39e
fix formatter
hulxv ca26274
trying to fix tests
hulxv 55da0b3
fixing failed tests
hulxv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
libcxx/test/libcxx/utilities/expected/expected.expected/nodiscard.verify.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14, c++17 | ||
hulxv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
// <expected> | ||
|
||
// Test that std::expected generates [[nodiscard]] warnings | ||
hulxv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
#include <expected> | ||
|
||
std::expected<int, int> returns_expected() { | ||
return std::expected<int, int>(5); | ||
} | ||
|
||
std::expected<void, int> returns_expected_void() { | ||
return std::expected<void, int>(); | ||
} | ||
|
||
void test() { | ||
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
returns_expected(); | ||
hulxv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
returns_expected_void(); | ||
} | ||
hulxv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.