<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">We warn if it is just one occurance and next literal is not split too. I changed test to test other scenario. I could add that test back, but I think we have enough tests to cover code.<div><br></div><div>We should not warn for code pattern:<div>{</div><div>“a” “b”,</div><div>“c” “d”</div><div>}</div><div><br></div><div><br></div><div><br><div dir="ltr"><br><blockquote type="cite">Dňa 9. 8. 2020 o 17:49 užívateľ Arthur O'Dwyer <arthur.j.odwyer@gmail.com> napísal:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div>Hi Dávid,</div><div>Does this part of the patch imply that we <b><i>don't </i></b>want to warn on</div><div>    "foo" TWO</div><div>? and if so, why not?</div><div>Anyway, I think at least</div><div>    "foo" TWO</div><div>should be kept in the test suite, as a test-for-absence-of-warning.</div><div><br></div><div dir="ltr">                              TWO "bar", <br>-                             "foo" TWO // expected-note{{place parentheses around the string literal to silence warning}}<br>+                             "foo" "bar" TWO // expected-note{{place parentheses around the string literal to silence warning}}</div><div dir="ltr"><br></div><div>my $.02,</div><div>Arthur</div><div dir="ltr"><br><div dir="ltr">On Sun, Aug 9, 2020 at 10:03 AM Dávid Bolvanský via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br>
Author: Dávid Bolvanský<br>
Date: 2020-08-09T16:02:41+02:00<br>
New Revision: 975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e<br>
<br>
URL: <a href="https://github.com/llvm/llvm-project/commit/975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e</a><br>
DIFF: <a href="https://github.com/llvm/llvm-project/commit/975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/975467e4aa7ce1b8fcf4af0e25cdf053cfa8669e.diff</a><br>
<br>
LOG: [Diagnostics] Handle string concat pattern and avoid false positives<br>
<br>
Added: <br>
<br>
<br>
Modified: <br>
    clang/lib/Sema/SemaExpr.cpp<br>
    clang/test/Sema/string-concat.c<br>
<br>
Removed: <br>
<br>
<br>
<br>
################################################################################<br>
diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp<br>
index 35047a7b2b14..74427f8cd7ae 100644<br>
--- a/clang/lib/Sema/SemaExpr.cpp<br>
+++ b/clang/lib/Sema/SemaExpr.cpp<br>
@@ -6908,10 +6908,13 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, MultiExprArg InitArgList,<br>
         << InitArgList[I]->getSourceRange();<br>
     } else if (const auto *SL = dyn_cast<StringLiteral>(InitArgList[I])) {<br>
       unsigned NumConcat = SL->getNumConcatenated();<br>
+      const auto *SLNext =<br>
+          dyn_cast<StringLiteral>(InitArgList[I + 1 < E ? I + 1 : 0]);<br>
       // Diagnose missing comma in string array initialization.<br>
-      // Do not warn when all the elements in the initializer are concatenated together.<br>
-      // Do not warn for macros too.<br>
-      if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID()) {<br>
+      // Do not warn when all the elements in the initializer are concatenated<br>
+      // together. Do not warn for macros too.<br>
+      if (NumConcat > 1 && E > 2 && !SL->getBeginLoc().isMacroID() && SLNext &&<br>
+          NumConcat != SLNext->getNumConcatenated()) {<br>
         SmallVector<FixItHint, 1> Hints;<br>
         for (unsigned i = 0; i < NumConcat - 1; ++i)<br>
           Hints.push_back(FixItHint::CreateInsertion(<br>
<br>
diff  --git a/clang/test/Sema/string-concat.c b/clang/test/Sema/string-concat.c<br>
index c93bbd4eaa00..13e9656d2536 100644<br>
--- a/clang/test/Sema/string-concat.c<br>
+++ b/clang/test/Sema/string-concat.c<br>
@@ -61,7 +61,7 @@ char missing_comma_inner[][5] = {<br>
 #define TWO "foo"<br>
 const char *macro_test[] = { ONE("foo") "bar", <br>
                              TWO "bar", <br>
-                             "foo" TWO // expected-note{{place parentheses around the string literal to silence warning}}<br>
+                             "foo" "bar" TWO // expected-note{{place parentheses around the string literal to silence warning}}<br>
                            };          // expected-warning@-1{{suspicious concatenation of string literals in an array initialization; did you mean to separate the elements with a comma?}}<br>
<br>
 // Do not warn for macros.<br>
@@ -104,6 +104,12 @@ const char *not_warn[] = {<br>
     "world", "test"<br>
 };<br>
<br>
+const char *not_warn2[] = {<br>
+    "// Aaa\\\n"   " Bbb\\ \n"   " Ccc?" "?/\n",<br>
+    "// Aaa\\\r\n" " Bbb\\ \r\n" " Ccc?" "?/\r\n",<br>
+    "// Aaa\\\r"   " Bbb\\ \r"   " Ccc?" "?/\r"<br>
+  };<br>
+<br>
 // Do not warn when all the elements in the initializer are concatenated together.<br>
 const char *all_elems_in_init_concatenated[] = {"a" "b" "c"};<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div></div>
</div></blockquote></div></div></body></html>