[clang] 2f7adf5 - [Diagnostics] Skip var decl of structs for -Wstring-concatenation
Dávid Bolvanský via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 13 11:20:42 PDT 2020
Author: Dávid Bolvanský
Date: 2020-08-13T20:20:26+02:00
New Revision: 2f7adf5ee37934ee5769276644fcafbc9d4dcda3
URL: https://github.com/llvm/llvm-project/commit/2f7adf5ee37934ee5769276644fcafbc9d4dcda3
DIFF: https://github.com/llvm/llvm-project/commit/2f7adf5ee37934ee5769276644fcafbc9d4dcda3.diff
LOG: [Diagnostics] Skip var decl of structs for -Wstring-concatenation
Added:
Modified:
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/string-concat.c
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index fee748bf9f9d..ab1496337210 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -12886,7 +12886,8 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
AttributeCommonInfo::AS_Pragma));
}
- if (var->hasInit() && isa<InitListExpr>(var->getInit())) {
+ if (!var->getType()->isStructureType() && var->hasInit() &&
+ isa<InitListExpr>(var->getInit())) {
const auto *ILE = cast<InitListExpr>(var->getInit());
unsigned NumInits = ILE->getNumInits();
if (NumInits > 2)
@@ -12927,7 +12928,7 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
Diag(SL->getBeginLoc(),
diag::note_concatenated_string_literal_silence);
}
- // Warn just once.
+ // In any case, stop now.
break;
}
}
diff --git a/clang/test/Sema/string-concat.c b/clang/test/Sema/string-concat.c
index b6bae9c95b0b..63abf100c020 100644
--- a/clang/test/Sema/string-concat.c
+++ b/clang/test/Sema/string-concat.c
@@ -148,6 +148,12 @@ const A not_warn6 = A{"",
""};
#endif
+static A not_warn7 = {"",
+
+ ""
+ "",
+ ""};
+
// Do not warn when all the elements in the initializer are concatenated together.
const char *all_elems_in_init_concatenated[] = {"a" "b" "c"};
More information about the cfe-commits
mailing list