[clang-tools-extra] [clang-tidy][test] Add more bugprone-string-constructor tests (PR #70456)

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 27 07:16:18 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-tidy

Author: ツ (maflcko)

<details>
<summary>Changes</summary>

Test:

* string literal concatenation is accepted
* escaped embedded null char is accepted
* taking over the implicit null char is rejected

---
Full diff: https://github.com/llvm/llvm-project/pull/70456.diff


1 Files Affected:

- (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/string-constructor.cpp (+4) 


``````````diff
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/string-constructor.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/string-constructor.cpp
index 1ca4d14f85e29d3..a5b6b240ddc665a 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/string-constructor.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/string-constructor.cpp
@@ -49,6 +49,8 @@ void Test() {
   // CHECK-MESSAGES: [[@LINE-1]]:15: warning: negative value used as length parameter
   std::string q2("test", 200);
   // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger than string literal size
+  std::string t1("test", 5);
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger than string literal size
   std::string q3(kText, 200);
   // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger than string literal size
   std::string q4(kText2, 200);
@@ -97,6 +99,8 @@ void Valid() {
   std::string s1("test", 4);
   std::string s2("test", 3);
   std::string s3("test");
+  std::string s4("test\000", 5);
+  std::string s6("te" "st", 4);
 
   std::string_view emptyv();
   std::string_view sv1("test", 4);

``````````

</details>


https://github.com/llvm/llvm-project/pull/70456


More information about the cfe-commits mailing list