forked from OSchip/llvm-project
[Diagnostics] Avoid false positives with -Wstring-concatenation
This commit is contained in:
parent
2c48e3629c
commit
62223ff137
|
@ -6908,13 +6908,15 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, MultiExprArg InitArgList,
|
|||
<< InitArgList[I]->getSourceRange();
|
||||
} else if (const auto *SL = dyn_cast<StringLiteral>(InitArgList[I])) {
|
||||
unsigned NumConcat = SL->getNumConcatenated();
|
||||
const auto *SLNext =
|
||||
dyn_cast<StringLiteral>(InitArgList[I + 1 < E ? I + 1 : 0]);
|
||||
const auto *SLPrev =
|
||||
dyn_cast<StringLiteral>(InitArgList[I == 0 ? E - 1 : I - 1]);
|
||||
// Diagnose missing comma in string array initialization.
|
||||
// Do not warn when all the elements in the initializer are concatenated
|
||||
// together. Do not warn for macros too.
|
||||
if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID() && SLNext &&
|
||||
NumConcat != SLNext->getNumConcatenated()) {
|
||||
if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID() &&
|
||||
SL->getString().find(" ") == llvm::StringRef::npos &&
|
||||
isa<StringLiteral>(InitArgList[0]) && SLPrev &&
|
||||
NumConcat != SLPrev->getNumConcatenated()) {
|
||||
SmallVector<FixItHint, 1> Hints;
|
||||
for (unsigned i = 0; i < NumConcat - 1; ++i)
|
||||
Hints.push_back(FixItHint::CreateInsertion(
|
||||
|
|
|
@ -108,7 +108,20 @@ const char *not_warn2[] = {
|
|||
"// Aaa\\\n" " Bbb\\ \n" " Ccc?" "?/\n",
|
||||
"// Aaa\\\r\n" " Bbb\\ \r\n" " Ccc?" "?/\r\n",
|
||||
"// Aaa\\\r" " Bbb\\ \r" " Ccc?" "?/\r"
|
||||
};
|
||||
};
|
||||
|
||||
const char *not_warn3[] = {
|
||||
"// \\param [in,out] aaa Bbb\n",
|
||||
"// \\param[in,out] aaa Bbb\n",
|
||||
"// \\param [in, out] aaa Bbb\n",
|
||||
"// \\param [in,\n"
|
||||
"// out] aaa Bbb\n",
|
||||
"// \\param [in,out]\n"
|
||||
"// aaa Bbb\n",
|
||||
"// \\param [in,out] aaa\n"
|
||||
"// Bbb\n"
|
||||
};
|
||||
|
||||
|
||||
// Do not warn when all the elements in the initializer are concatenated together.
|
||||
const char *all_elems_in_init_concatenated[] = {"a" "b" "c"};
|
||||
|
|
Loading…
Reference in New Issue