-
Notifications
You must be signed in to change notification settings - Fork 14.2k
[clang-tidy][performance-unnecessary-value-param] Avoid in coroutines #140912
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
dmpolukhin
merged 9 commits into
llvm:main
from
dmpolukhin:performance-unnecessary-value-param-coroutine
Jun 17, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f277796
[clang-tidy][performance-unnecessary-value-param] Avoid in coroutines
dmpolukhin 011624d
Add documentation and simplify test
dmpolukhin 6f53984
Move note to more appropiate place
dmpolukhin 4764091
Added option IsAllowedInCoroutines
dmpolukhin 082f1c8
Accepted suggested changes
dmpolukhin 2fc8017
Fix formatting
dmpolukhin c5b7dda
Remove unnecessary static_cast.
dmpolukhin c0c5fdc
s/IsAllowedInCoroutines/IgnoreCoroutines/ and invert logic
dmpolukhin eb791cc
Fix formatting
dmpolukhin 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
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
65 changes: 65 additions & 0 deletions
65
clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-coroutine.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,65 @@ | ||
// RUN: %check_clang_tidy -std=c++20-or-later %s performance-unnecessary-value-param %t -- -fix-errors | ||
// RUN: %check_clang_tidy -std=c++20-or-later %s performance-unnecessary-value-param %t -- \ | ||
// RUN: -config='{CheckOptions: {performance-unnecessary-value-param.IgnoreCoroutines: true}}' -fix-errors | ||
// RUN: %check_clang_tidy -check-suffix=ALLOWED -std=c++20-or-later %s performance-unnecessary-value-param %t -- \ | ||
// RUN: -config='{CheckOptions: {performance-unnecessary-value-param.IgnoreCoroutines: false}}' -fix-errors | ||
|
||
namespace std { | ||
|
||
template <class Ret, typename... T> struct coroutine_traits { | ||
using promise_type = typename Ret::promise_type; | ||
}; | ||
|
||
template <class Promise = void> struct coroutine_handle { | ||
static coroutine_handle from_address(void *) noexcept; | ||
static coroutine_handle from_promise(Promise &promise); | ||
constexpr void *address() const noexcept; | ||
}; | ||
|
||
template <> struct coroutine_handle<void> { | ||
template <class PromiseType> | ||
coroutine_handle(coroutine_handle<PromiseType>) noexcept; | ||
static coroutine_handle from_address(void *); | ||
constexpr void *address() const noexcept; | ||
}; | ||
|
||
struct suspend_always { | ||
bool await_ready() noexcept { return false; } | ||
void await_suspend(coroutine_handle<>) noexcept {} | ||
void await_resume() noexcept {} | ||
}; | ||
|
||
struct suspend_never { | ||
bool await_ready() noexcept { return true; } | ||
void await_suspend(coroutine_handle<>) noexcept {} | ||
void await_resume() noexcept {} | ||
}; | ||
|
||
} // namespace std | ||
|
||
struct ReturnObject { | ||
struct promise_type { | ||
ReturnObject get_return_object() { return {}; } | ||
ReturnObject return_void() { return {}; } | ||
std::suspend_always initial_suspend() { return {}; } | ||
std::suspend_always final_suspend() noexcept { return {}; } | ||
void unhandled_exception() {} | ||
std::suspend_always yield_value(int value) { return {}; } | ||
}; | ||
}; | ||
|
||
struct A { | ||
A(const A&); | ||
}; | ||
|
||
ReturnObject foo_coroutine(const A a) { | ||
// CHECK-MESSAGES-ALLOWED: [[@LINE-1]]:36: warning: the const qualified parameter 'a' | ||
// CHECK-FIXES: ReturnObject foo_coroutine(const A a) { | ||
co_return; | ||
} | ||
|
||
ReturnObject foo_not_coroutine(const A a) { | ||
// CHECK-MESSAGES: [[@LINE-1]]:40: warning: the const qualified parameter 'a' | ||
// CHECK-MESSAGES-ALLOWED: [[@LINE-2]]:40: warning: the const qualified parameter 'a' | ||
return ReturnObject{}; | ||
} |
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.