66 lines · cpp
1// RUN: %check_clang_tidy -std=c++20-or-later %s performance-unnecessary-value-param %t -- -fix-errors2// RUN: %check_clang_tidy -std=c++20-or-later %s performance-unnecessary-value-param %t -- \3// RUN: -config='{CheckOptions: {performance-unnecessary-value-param.IgnoreCoroutines: true}}' -fix-errors4// RUN: %check_clang_tidy -check-suffix=ALLOWED -std=c++20-or-later %s performance-unnecessary-value-param %t -- \5// RUN: -config='{CheckOptions: {performance-unnecessary-value-param.IgnoreCoroutines: false}}' -fix-errors6 7namespace std {8 9template <class Ret, typename... T> struct coroutine_traits {10 using promise_type = typename Ret::promise_type;11};12 13template <class Promise = void> struct coroutine_handle {14 static coroutine_handle from_address(void *) noexcept;15 static coroutine_handle from_promise(Promise &promise);16 constexpr void *address() const noexcept;17};18 19template <> struct coroutine_handle<void> {20 template <class PromiseType>21 coroutine_handle(coroutine_handle<PromiseType>) noexcept;22 static coroutine_handle from_address(void *);23 constexpr void *address() const noexcept;24};25 26struct suspend_always {27 bool await_ready() noexcept { return false; }28 void await_suspend(coroutine_handle<>) noexcept {}29 void await_resume() noexcept {}30};31 32struct suspend_never {33 bool await_ready() noexcept { return true; }34 void await_suspend(coroutine_handle<>) noexcept {}35 void await_resume() noexcept {}36};37 38} // namespace std39 40struct ReturnObject {41 struct promise_type {42 ReturnObject get_return_object() { return {}; }43 ReturnObject return_void() { return {}; }44 std::suspend_always initial_suspend() { return {}; }45 std::suspend_always final_suspend() noexcept { return {}; }46 void unhandled_exception() {}47 std::suspend_always yield_value(int value) { return {}; }48 };49};50 51struct A {52 A(const A&);53};54 55ReturnObject foo_coroutine(const A a) {56// CHECK-MESSAGES-ALLOWED: [[@LINE-1]]:36: warning: the const qualified parameter 'a'57// CHECK-FIXES: ReturnObject foo_coroutine(const A a) {58 co_return;59}60 61ReturnObject foo_not_coroutine(const A a) {62// CHECK-MESSAGES: [[@LINE-1]]:40: warning: the const qualified parameter 'a'63// CHECK-MESSAGES-ALLOWED: [[@LINE-2]]:40: warning: the const qualified parameter 'a'64 return ReturnObject{};65}66