-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[libc++][span] Mark functions as [[nodiscard]]
#168033
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
Merged
+129
−37
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
334f144
[libc++][span] Mark functions as `[[nodiscard]]`
H-G-Hristov 9134962
Update libcxx/test/libcxx/containers/views/views.span/nodiscard.verif…
Zingam 34ea8ee
Update libcxx/test/libcxx/containers/views/views.span/nodiscard.verif…
Zingam fb96a81
Apply suggestion from @Zingam
Zingam 1fee6e0
Apply suggestion from @Zingam
Zingam de00bf4
Fix the fix
H-G-Hristov 0b01b42
Cleanup
H-G-Hristov 423da0b
Addressed comments
H-G-Hristov 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
78 changes: 78 additions & 0 deletions
78
libcxx/test/libcxx/containers/views/views.span/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,78 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // REQUIRES: std-at-least-c++20 | ||
|
|
||
| // <span> | ||
|
|
||
| // Check that functions are marked [[nodiscard]] | ||
|
|
||
| #include <array> | ||
| #include <span> | ||
| #include <vector> | ||
Zingam marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #include "test_macros.h" | ||
|
|
||
| void test() { | ||
| { // Test with a static extent | ||
| std::span<int, 2> sp; | ||
|
|
||
| sp.first<1>(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.last<1>(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.first(1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.last(1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.subspan<0, 1>(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.subspan(0, 1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.size(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.size_bytes(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp[0]; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| #if TEST_STD_VER >= 26 | ||
| sp.at(0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| #endif | ||
| sp.front(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.back(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.data(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.end(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.rbegin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.rend(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
|
|
||
| std::as_bytes(sp); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| std::as_writable_bytes(sp); | ||
| } | ||
| { // Test with a dynamic extent | ||
| std::span<int> sp; | ||
|
|
||
| sp.first<1>(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.last<1>(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.first(1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.last(1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.subspan<0, 1>(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.subspan(0, 1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.size(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.size_bytes(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp[0]; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| #if TEST_STD_VER >= 26 | ||
| sp.at(0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| #endif | ||
| sp.front(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.back(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.data(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.end(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.rbegin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| sp.rend(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
|
|
||
| std::as_bytes(sp); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| std::as_writable_bytes(sp); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.