Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ void RvalueReferenceParamNotMovedCheck::check(
if (IgnoreUnnamedParams && Param->getName().empty())
return;

if (!Param->isUsed() && Param->hasAttr<UnusedAttr>())
return;

const auto *Function = dyn_cast<FunctionDecl>(Param->getDeclContext());
if (!Function)
return;
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ Changes in existing checks
<clang-tidy/checks/cppcoreguidelines/pro-type-vararg>` check to ignore
false-positives in unevaluated context (e.g., ``decltype``, ``sizeof``, ...).

- Improved :doc:`cppcoreguidelines-rvalue-reference-param-not-moved
<clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved>` check
to ignore unused parameters when they are marked as unused.

- Improved :doc:`llvm-namespace-comment
<clang-tidy/checks/llvm/namespace-comment>` check to provide fixes for
``inline`` namespaces in the same format as :program:`clang-format`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ Example:
std::string Copy(Input); // Oops - forgot to std::move
}

Note that parameters that are unused and marked as such will not be diagnosed.

Example:

.. code-block:: c++

void conditional_use([[maybe_unused]] std::string&& Input) {
// No diagnostic here since Input is unused and marked as such
}

Options
-------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,28 @@ void instantiate_a_class_template() {
AClassTemplate<Obj&> withObjRef(o);
withObjRef.never_moves(o);
}

namespace gh68209
{
void f1([[maybe_unused]] int&& x) {}

void f2(__attribute__((unused)) int&& x) {}

void f3(int&& x) {}
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: rvalue reference parameter 'x' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]

template <typename T>
void f4([[maybe_unused]] T&& x) {}

template <typename T>
void f5(__attribute((unused)) T&& x) {}

template<typename T>
void f6(T&& x) {}

void f7([[maybe_unused]] int&& x) { x += 1; }
// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: rvalue reference parameter 'x' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]

void f8(__attribute__((unused)) int&& x) { x += 1; }
// CHECK-MESSAGES: :[[@LINE-1]]:41: warning: rvalue reference parameter 'x' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
} // namespace gh68209