Open firewave opened 4 months ago
@llvm/issue-subscribers-clang-tidy
Author: Oliver Stöneberg (firewave)
A more simplified case is being detected:
#include <string>
void f()
{
std::string str;
const auto s = str;
if (s.empty()) {}
}
<source>:6:16: warning: local copy 's' of the variable 'str' is never modified; consider avoiding the copy [performance-unnecessary-copy-initialization]
6 | const auto s = str;
| ^
| &
Small variations prevent detection:
void f()
{
std::string str;
//const auto s = std::string(str.begin(), str.end()); // FN
const std::string s(str.begin(), str.end()); // FN
if (s.empty()) {}
}
https://godbolt.org/z/31r8d3vfP