[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:15:10 PDT 2023


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

Test:

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

>From fa93a9851f03c5ae67299f5b37f7594ca67396e1 Mon Sep 17 00:00:00 2001
From: MarcoFalke <*~=`'#}+{/-|&$^_ at 721217.xyz>
Date: Fri, 27 Oct 2023 16:11:26 +0200
Subject: [PATCH] [clang-tidy][test] Add more bugprone-string-constructor tests

---
 .../test/clang-tidy/checkers/bugprone/string-constructor.cpp  | 4 ++++
 1 file changed, 4 insertions(+)

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);



More information about the cfe-commits mailing list