clang-tidy module: fix offset issue with last string concat operand
This commit is contained in:
parent
3d019b4133
commit
b1366e215e
@ -156,7 +156,8 @@ void StringConcatenationUseCmstrcatCheck::issueCorrection(
|
||||
ExprNode = *It;
|
||||
|
||||
StringRef LastToken = Lexer::getSourceText(
|
||||
CharSourceRange::getTokenRange(ExprNode->getArg(1)->getSourceRange()),
|
||||
CharSourceRange::getTokenRange(
|
||||
ExprNode->getArg(1)->getSourceRange().getEnd()),
|
||||
Result.Context->getSourceManager(), Result.Context->getLangOpts());
|
||||
FixIts.push_back(FixItHint::CreateInsertion(
|
||||
ExprNode->getEndLoc().getLocWithOffset(LastToken.str().size()), ")"));
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
template <typename... Args>
|
||||
std::string cmStrCat(Args&&... args)
|
||||
@ -24,6 +25,9 @@ void test1()
|
||||
concat = cmStrCat(concat, " and this is a string literal");
|
||||
concat = cmStrCat(concat, 'o');
|
||||
concat = cmStrCat(concat, b, " and this is a string literal ", 'o', b);
|
||||
|
||||
std::pair<std::string, std::string> p;
|
||||
concat = cmStrCat(p.first, p.second);
|
||||
}
|
||||
|
||||
// No correction needed
|
||||
|
@ -1,113 +1,124 @@
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:16:12: warning: use cmStrCat() instead of string concatenation [cmake-string-concatenation-use-cmstrcat]
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:17:12: warning: use cmStrCat() instead of string concatenation [cmake-string-concatenation-use-cmstrcat]
|
||||
concat = a + b;
|
||||
^ ~
|
||||
cmStrCat( , )
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:16:12: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:16:14: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:17:12: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:17:14: note: FIX-IT applied suggested code changes
|
||||
concat = a + b;
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:16:17: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:17:17: note: FIX-IT applied suggested code changes
|
||||
concat = a + b;
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:17:12: warning: use cmStrCat() instead of string concatenation [cmake-string-concatenation-use-cmstrcat]
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:18:12: warning: use cmStrCat() instead of string concatenation [cmake-string-concatenation-use-cmstrcat]
|
||||
concat = a + " and this is a string literal";
|
||||
^ ~
|
||||
cmStrCat( , )
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:17:12: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:17:14: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:18:12: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:18:14: note: FIX-IT applied suggested code changes
|
||||
concat = a + " and this is a string literal";
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:17:47: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:18:47: note: FIX-IT applied suggested code changes
|
||||
concat = a + " and this is a string literal";
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:18:12: warning: use cmStrCat() instead of string concatenation [cmake-string-concatenation-use-cmstrcat]
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:19:12: warning: use cmStrCat() instead of string concatenation [cmake-string-concatenation-use-cmstrcat]
|
||||
concat = a + 'O';
|
||||
^ ~
|
||||
cmStrCat( , )
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:18:12: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:18:14: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:19:12: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:19:14: note: FIX-IT applied suggested code changes
|
||||
concat = a + 'O';
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:18:19: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:19:19: note: FIX-IT applied suggested code changes
|
||||
concat = a + 'O';
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:19:12: warning: use cmStrCat() instead of string concatenation [cmake-string-concatenation-use-cmstrcat]
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:20:12: warning: use cmStrCat() instead of string concatenation [cmake-string-concatenation-use-cmstrcat]
|
||||
concat = "This is a string literal" + b;
|
||||
^ ~
|
||||
cmStrCat( , )
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:19:12: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:19:39: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:20:12: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:20:39: note: FIX-IT applied suggested code changes
|
||||
concat = "This is a string literal" + b;
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:19:42: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:20:42: note: FIX-IT applied suggested code changes
|
||||
concat = "This is a string literal" + b;
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:20:12: warning: use cmStrCat() instead of string concatenation [cmake-string-concatenation-use-cmstrcat]
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:21:12: warning: use cmStrCat() instead of string concatenation [cmake-string-concatenation-use-cmstrcat]
|
||||
concat = 'O' + a;
|
||||
^ ~
|
||||
cmStrCat( , )
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:20:12: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:20:16: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:21:12: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:21:16: note: FIX-IT applied suggested code changes
|
||||
concat = 'O' + a;
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:20:19: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:21:19: note: FIX-IT applied suggested code changes
|
||||
concat = 'O' + a;
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:21:12: warning: use cmStrCat() instead of string concatenation [cmake-string-concatenation-use-cmstrcat]
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:22:12: warning: use cmStrCat() instead of string concatenation [cmake-string-concatenation-use-cmstrcat]
|
||||
concat = a + " and this is a string literal" + 'O' + b;
|
||||
^ ~ ~ ~
|
||||
cmStrCat( , , , )
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:21:12: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:21:14: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:22:12: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:22:14: note: FIX-IT applied suggested code changes
|
||||
concat = a + " and this is a string literal" + 'O' + b;
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:21:48: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:22:48: note: FIX-IT applied suggested code changes
|
||||
concat = a + " and this is a string literal" + 'O' + b;
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:21:54: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:22:54: note: FIX-IT applied suggested code changes
|
||||
concat = a + " and this is a string literal" + 'O' + b;
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:21:57: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:22:57: note: FIX-IT applied suggested code changes
|
||||
concat = a + " and this is a string literal" + 'O' + b;
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:23:10: warning: use cmStrCat() instead of string append [cmake-string-concatenation-use-cmstrcat]
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:24:10: warning: use cmStrCat() instead of string append [cmake-string-concatenation-use-cmstrcat]
|
||||
concat += b;
|
||||
^~
|
||||
= cmStrCat(concat, )
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:23:10: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:23:14: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:24:10: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:24:14: note: FIX-IT applied suggested code changes
|
||||
concat += b;
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:24:10: warning: use cmStrCat() instead of string append [cmake-string-concatenation-use-cmstrcat]
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:25:10: warning: use cmStrCat() instead of string append [cmake-string-concatenation-use-cmstrcat]
|
||||
concat += " and this is a string literal";
|
||||
^~
|
||||
= cmStrCat(concat, )
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:24:10: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:24:44: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:25:10: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:25:44: note: FIX-IT applied suggested code changes
|
||||
concat += " and this is a string literal";
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:25:10: warning: use cmStrCat() instead of string append [cmake-string-concatenation-use-cmstrcat]
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:26:10: warning: use cmStrCat() instead of string append [cmake-string-concatenation-use-cmstrcat]
|
||||
concat += 'o';
|
||||
^~
|
||||
= cmStrCat(concat, )
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:25:10: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:25:16: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:26:10: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:26:16: note: FIX-IT applied suggested code changes
|
||||
concat += 'o';
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:26:10: warning: use cmStrCat() instead of string append [cmake-string-concatenation-use-cmstrcat]
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:27:10: warning: use cmStrCat() instead of string append [cmake-string-concatenation-use-cmstrcat]
|
||||
concat += b + " and this is a string literal " + 'o' + b;
|
||||
^~ ~ ~ ~
|
||||
= cmStrCat(concat, , , , )
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:26:10: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:26:15: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:27:10: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:27:15: note: FIX-IT applied suggested code changes
|
||||
concat += b + " and this is a string literal " + 'o' + b;
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:26:50: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:27:50: note: FIX-IT applied suggested code changes
|
||||
concat += b + " and this is a string literal " + 'o' + b;
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:26:56: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:27:56: note: FIX-IT applied suggested code changes
|
||||
concat += b + " and this is a string literal " + 'o' + b;
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:26:59: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:27:59: note: FIX-IT applied suggested code changes
|
||||
concat += b + " and this is a string literal " + 'o' + b;
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:30:12: warning: use cmStrCat() instead of string concatenation [cmake-string-concatenation-use-cmstrcat]
|
||||
concat = p.first + p.second;
|
||||
^ ~
|
||||
cmStrCat( , )
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:30:12: note: FIX-IT applied suggested code changes
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:30:20: note: FIX-IT applied suggested code changes
|
||||
concat = p.first + p.second;
|
||||
^
|
||||
cmake-string-concatenation-use-cmstrcat.cxx:30:30: note: FIX-IT applied suggested code changes
|
||||
concat = p.first + p.second;
|
||||
^
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
template <typename... Args>
|
||||
std::string cmStrCat(Args&&... args)
|
||||
@ -24,6 +25,9 @@ void test1()
|
||||
concat += " and this is a string literal";
|
||||
concat += 'o';
|
||||
concat += b + " and this is a string literal " + 'o' + b;
|
||||
|
||||
std::pair<std::string, std::string> p;
|
||||
concat = p.first + p.second;
|
||||
}
|
||||
|
||||
// No correction needed
|
||||
|
Loading…
Reference in New Issue
Block a user