mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
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).
52 lines
1.0 KiB
C++
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;
|
|
}
|