llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.63k stars 11.83k forks source link

cppcoreguidelines-rvalue-reference-param-not-moved false-positive for assignment operator? #113354

Open EugeneZelenko opened 2 hours ago

EugeneZelenko commented 2 hours ago

I may be wrong, but looks like cppcoreguidelines-rvalue-reference-param-not-moved produces false positive when assignment operator with rvalue is available (https://en.cppreference.com/w/cpp/string/basic_string/operator%3D):

#include <string>
#include <vector>

std::vector<std::string> tokens;

void function(std::string&& token)
{
    tokens.resize(tokens.size() + 1);
    tokens[tokens.size() - 1] = token;
}

GodBolt: https://godbolt.org/z/9zhvr75db

llvmbot commented 2 hours ago

@llvm/issue-subscribers-clang-tidy

Author: None (EugeneZelenko)

I may be wrong, but looks like `cppcoreguidelines-rvalue-reference-param-not-moved` produces false positive when assignment operator with rvalue is available (https://en.cppreference.com/w/cpp/string/basic_string/operator%3D): ``` #include <string> #include <vector> std::vector<std::string> tokens; void function(std::string&& token) { tokens.resize(tokens.size() + 1); tokens[tokens.size() - 1] = token; } ``` GodBolt: https://godbolt.org/z/9zhvr75db