Files
cmake/Utilities/ClangTidyModule/Tests/cmake-string-concatenation-use-cmstrcat-fixit.cxx
T
AJIOB 182473210f clang-tidy: not suggest cmStrCat for short appends and concats
We rely, that standard library have really effective `+=` and `+` operators
for `std::string` with any paired arguments: `std::string`, `const char *` and `char`.
So, that change just blocks `c = a + b` and `c += a` replacements,
but still replaces the `c = a + b + d` and `c += a + b` and longer (with more `+` operators).
2026-09-22 10:31:17 +03:00

52 lines
1.0 KiB
C++

#include <string>
#include <utility>
template <typename... Args>
std::string cmStrCat(Args&&... args)
{
return "";
}
std::string a = "This is a string variable";
std::string b = " and this is a string variable";
std::string concat;
// Correction needed
void test1()
{
concat = cmStrCat(a, " and this is a string literal", 'O', b);
concat = cmStrCat(concat, a, a);
concat = cmStrCat(concat, " and this is a string literal", a);
concat = cmStrCat(concat, b, 'o', a);
concat = cmStrCat(concat, b, " and this is a string literal ", 'o', b);
if (true)
concat = cmStrCat(concat, a, b);
std::pair<std::string, std::string> p;
concat = cmStrCat(p.first, p.second, a);
}
// No correction needed
void test2()
{
a = b;
a = "This is a string literal";
a = 'X';
cmStrCat(a, b);
concat = a + b;
concat = a + " and this is a string literal";
concat = a + 'O';
concat = "This is a string literal" + b;
concat = 'O' + a;
concat += b;
std::pair<std::string, std::string> p;
concat = p.first + p.second;
if (true)
concat += a;
}