Skip to content

Commit 2f7adf5

Browse files
[Diagnostics] Skip var decl of structs for -Wstring-concatenation
1 parent e137b55 commit 2f7adf5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12886,7 +12886,8 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
1288612886
AttributeCommonInfo::AS_Pragma));
1288712887
}
1288812888

12889-
if (var->hasInit() && isa<InitListExpr>(var->getInit())) {
12889+
if (!var->getType()->isStructureType() && var->hasInit() &&
12890+
isa<InitListExpr>(var->getInit())) {
1289012891
const auto *ILE = cast<InitListExpr>(var->getInit());
1289112892
unsigned NumInits = ILE->getNumInits();
1289212893
if (NumInits > 2)
@@ -12927,7 +12928,7 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
1292712928
Diag(SL->getBeginLoc(),
1292812929
diag::note_concatenated_string_literal_silence);
1292912930
}
12930-
// Warn just once.
12931+
// In any case, stop now.
1293112932
break;
1293212933
}
1293312934
}

clang/test/Sema/string-concat.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ const A not_warn6 = A{"",
148148
""};
149149
#endif
150150

151+
static A not_warn7 = {"",
152+
153+
""
154+
"",
155+
""};
156+
151157

152158
// Do not warn when all the elements in the initializer are concatenated together.
153159
const char *all_elems_in_init_concatenated[] = {"a" "b" "c"};

0 commit comments

Comments
 (0)