From 2e84f57c19a46b707fe89128279670ed1b55da66 Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Thu, 23 Nov 2017 13:49:14 +0000 Subject: [clang-tidy] rename_check.py misc-string-constructor bugprone-string-constructor Summary: Rename misc-string-constructor to bugprone-string-constructor + manually update the lenght of '==='s in the doc file. Reviewers: hokein, xazax.hun Reviewed By: hokein, xazax.hun Subscribers: mgorny, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D40388 git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@318916 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/clang-tidy/bugprone-string-constructor.cpp | 56 +++++++++++++++++++++++++ test/clang-tidy/misc-string-constructor.cpp | 56 ------------------------- 2 files changed, 56 insertions(+), 56 deletions(-) create mode 100644 test/clang-tidy/bugprone-string-constructor.cpp delete mode 100644 test/clang-tidy/misc-string-constructor.cpp (limited to 'test') diff --git a/test/clang-tidy/bugprone-string-constructor.cpp b/test/clang-tidy/bugprone-string-constructor.cpp new file mode 100644 index 00000000..51d91305 --- /dev/null +++ b/test/clang-tidy/bugprone-string-constructor.cpp @@ -0,0 +1,56 @@ +// RUN: %check_clang_tidy %s bugprone-string-constructor %t + +namespace std { +template +class allocator {}; +template +class char_traits {}; +template , typename A = std::allocator > +struct basic_string { + basic_string(); + basic_string(const C*, unsigned int size); + basic_string(unsigned int size, C c); +}; +typedef basic_string string; +typedef basic_string wstring; +} + +const char* kText = ""; +const char kText2[] = ""; +extern const char kText3[]; + +void Test() { + std::string str('x', 4); + // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor parameters are probably swapped; expecting string(count, character) [bugprone-string-constructor] + // CHECK-FIXES: std::string str(4, 'x'); + std::wstring wstr(L'x', 4); + // CHECK-MESSAGES: [[@LINE-1]]:16: warning: string constructor parameters are probably swapped + // CHECK-FIXES: std::wstring wstr(4, L'x'); + std::string s0(0, 'x'); + // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor creating an empty string + std::string s1(-4, 'x'); + // CHECK-MESSAGES: [[@LINE-1]]:15: warning: negative value used as length parameter + std::string s2(0x1000000, 'x'); + // CHECK-MESSAGES: [[@LINE-1]]:15: warning: suspicious large length parameter + + std::string q0("test", 0); + // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor creating an empty string + std::string q1(kText, -4); + // 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 then string literal size + std::string q3(kText, 200); + // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger then string literal size + std::string q4(kText2, 200); + // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger then string literal size + std::string q5(kText3, 0x1000000); + // CHECK-MESSAGES: [[@LINE-1]]:15: warning: suspicious large length parameter +} + +void Valid() { + std::string empty(); + std::string str(4, 'x'); + std::wstring wstr(4, L'x'); + std::string s1("test", 4); + std::string s2("test", 3); +} diff --git a/test/clang-tidy/misc-string-constructor.cpp b/test/clang-tidy/misc-string-constructor.cpp deleted file mode 100644 index 85ae7450..00000000 --- a/test/clang-tidy/misc-string-constructor.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// RUN: %check_clang_tidy %s misc-string-constructor %t - -namespace std { -template -class allocator {}; -template -class char_traits {}; -template , typename A = std::allocator > -struct basic_string { - basic_string(); - basic_string(const C*, unsigned int size); - basic_string(unsigned int size, C c); -}; -typedef basic_string string; -typedef basic_string wstring; -} - -const char* kText = ""; -const char kText2[] = ""; -extern const char kText3[]; - -void Test() { - std::string str('x', 4); - // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor parameters are probably swapped; expecting string(count, character) [misc-string-constructor] - // CHECK-FIXES: std::string str(4, 'x'); - std::wstring wstr(L'x', 4); - // CHECK-MESSAGES: [[@LINE-1]]:16: warning: string constructor parameters are probably swapped - // CHECK-FIXES: std::wstring wstr(4, L'x'); - std::string s0(0, 'x'); - // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor creating an empty string - std::string s1(-4, 'x'); - // CHECK-MESSAGES: [[@LINE-1]]:15: warning: negative value used as length parameter - std::string s2(0x1000000, 'x'); - // CHECK-MESSAGES: [[@LINE-1]]:15: warning: suspicious large length parameter - - std::string q0("test", 0); - // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor creating an empty string - std::string q1(kText, -4); - // 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 then string literal size - std::string q3(kText, 200); - // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger then string literal size - std::string q4(kText2, 200); - // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger then string literal size - std::string q5(kText3, 0x1000000); - // CHECK-MESSAGES: [[@LINE-1]]:15: warning: suspicious large length parameter -} - -void Valid() { - std::string empty(); - std::string str(4, 'x'); - std::wstring wstr(4, L'x'); - std::string s1("test", 4); - std::string s2("test", 3); -} -- cgit v1.2.3