Skip to content

[clang-tidy] False positive for cppcoreguidelines-rvalue-reference-param-not-moved when parameter has [[maybe_unused]] #68209

@nilssonk

Description

@nilssonk

The following seemingly valid code

#include <tuple>
#include <utility>

void conditional_use([[maybe_unused]] int && x) {
#ifdef USE_X
    int y = std::move(x);
    std::ignore = y;
#endif
}

int main() {
    conditional_use(5);
}

results in the error

repro.cpp:4:46: error: rvalue reference parameter 'x' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved,-warnings-as-errors]
    4 | void conditional_use([[maybe_unused]] int && x) {

Encountered on

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:        22.04
Codename:       jammy
$ clang-tidy --version
Ubuntu LLVM version 17.0.2
  Optimized build.

installed with the script from https://apt.llvm.org/llvm.sh .

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions