Skip to content

Commit b62c144

Browse files
committed
add test for multiple consecutive missing commas
1 parent d9cd867 commit b62c144

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14710,11 +14710,9 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
1471014710
unsigned NumInits = ILE->getNumInits();
1471114711
if (NumInits > 2) {
1471214712
auto concatenatedPartsAt = [&](unsigned Index) -> unsigned {
14713-
const Expr *E = ILE->getInit(Index);
14714-
if (E) {
14713+
if (const Expr *E = ILE->getInit(Index))
1471514714
if (const auto *S = dyn_cast<StringLiteral>(E->IgnoreImpCasts()))
1471614715
return S->getNumConcatenated();
14717-
}
1471814716
return 0;
1471914717
};
1472014718

@@ -14738,11 +14736,11 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
1473814736
unsigned R = I + 1 < NumInits ? concatenatedPartsAt(I + 1) : 0;
1473914737

1474014738
// Skip neighbors with multi-part concatenations.
14741-
if (L > 1 || R > 1)
14739+
if (R > 1)
1474214740
continue;
1474314741

1474414742
// Diagnose when at least one neighbor is a single literal.
14745-
if (L || R) {
14743+
if (R == 1 || L == 1) {
1474614744
SmallVector<FixItHint, 1> Hints;
1474714745
// Insert a comma between the two tokens of this element.
1474814746
Hints.push_back(FixItHint::CreateInsertion(

clang/test/Sema/string-concat.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ const char *extra_parens_to_suppress_warning[] = {
169169
"shared_future"
170170
};
171171

172-
const char *multiple_missing_commas[] = {
172+
const char *multiple_missing_commas1[] = {
173173
"1",
174174
"2" // expected-note {{place parentheses around the string literal to silence warning}}
175175
"3", // expected-warning {{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}
@@ -182,3 +182,17 @@ const char *multiple_missing_commas[] = {
182182
"10",
183183
"11",
184184
};
185+
186+
const char *multiple_missing_commas2[] = {
187+
"1",
188+
"2"
189+
"3"
190+
"4"
191+
"5",
192+
"6" // expected-note {{place parentheses around the string literal to silence warning}}
193+
"7", // expected-warning {{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}
194+
"8",
195+
"9",
196+
"10",
197+
"11",
198+
};

0 commit comments

Comments
 (0)