llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-tools-extra Author: Baranov Victor (vbvictor) <details> <summary>Changes</summary> --- Patch is 20.73 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/183996.diff 17 Files Affected: - (modified) clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string (+25-5) - (modified) clang-tools-extra/test/clang-tidy/checkers/abseil/string-find-str-contains.cpp (+5) - (modified) clang-tools-extra/test/clang-tidy/checkers/boost/use-to-string.cpp (+2-10) - (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp (+1-22) - (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters-prefixsuffixname.cpp (+2-4) - (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-container.cpp (+4-21) - (modified) clang-tools-extra/test/clang-tidy/checkers/bugprone/string-integer-assignment.cpp (+2-14) - (modified) clang-tools-extra/test/clang-tidy/checkers/modernize/use-nodiscard.cpp (+3-2) - (modified) clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-transform-lambdas-cxx14.cpp (+1-4) - (modified) clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-transform-lambdas.cpp (+1-4) - (modified) clang-tools-extra/test/clang-tidy/checkers/performance/faster-string-find.cpp (+3-38) - (modified) clang-tools-extra/test/clang-tidy/checkers/performance/inefficient-string-concatenation.cpp (+2-14) - (modified) clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static-deducing-this.cpp (+2-2) - (modified) clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return.cpp (+2-8) - (modified) clang-tools-extra/test/clang-tidy/checkers/readability/isolate-declaration-cxx17.cpp (+1-14) - (modified) clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-init.cpp (+2-31) - (modified) clang-tools-extra/test/clang-tidy/checkers/readability/simplify-subscript-expr.cpp (+3-34) ``````````diff diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string index fc197d0afa714..3631c0330c427 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string +++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string @@ -61,6 +61,11 @@ struct basic_string { size_type rfind(const C* s, size_type pos = npos) const; size_type rfind(C ch, size_type pos = npos) const; + size_type find_first_of(const C* s, size_type pos = 0) const; + size_type find_first_not_of(const C* s, size_type pos = 0) const; + size_type find_last_of(const C* s, size_type pos = npos) const; + size_type find_last_not_of(const C* s, size_type pos = npos) const; + constexpr bool contains(std::basic_string_view<C, T> sv) const noexcept; constexpr bool contains(C ch) const noexcept; constexpr bool contains(const C* s) const; @@ -79,13 +84,15 @@ struct basic_string { constexpr bool ends_with(C ch) const noexcept; constexpr bool ends_with(const C* s) const; - _Type& operator[](size_type); - const _Type& operator[](size_type) const; + C& operator[](size_type); + const C& operator[](size_type) const; _Type& operator+=(const _Type& str); _Type& operator+=(const C* s); + _Type& operator+=(C ch); _Type& operator=(const _Type& str); _Type& operator=(const C* s); + _Type& operator=(C ch); static constexpr size_t npos = -1; }; @@ -107,10 +114,14 @@ struct basic_string_view { typedef basic_string_view<C, T> _Type; const C *str; + constexpr basic_string_view() : str(nullptr) {} constexpr basic_string_view(const C* s) : str(s) {} + constexpr basic_string_view(const C* s, size_type) : str(s) {} const C *data() const; + constexpr const C &operator[](size_type pos) const; + bool empty() const; size_type size() const; size_type length() const; @@ -125,6 +136,11 @@ struct basic_string_view { size_type rfind(const C* s, size_type pos, size_type count) const; size_type rfind(const C* s, size_type pos = npos) const; + size_type find_first_of(const C* s, size_type pos = 0) const; + size_type find_first_not_of(const C* s, size_type pos = 0) const; + size_type find_last_of(const C* s, size_type pos = npos) const; + size_type find_last_not_of(const C* s, size_type pos = npos) const; + constexpr bool contains(basic_string_view sv) const noexcept; constexpr bool contains(C ch) const noexcept; constexpr bool contains(const C* s) const; @@ -157,6 +173,10 @@ std::string operator+(const std::string&, const std::string&); std::string operator+(const std::string&, const char*); std::string operator+(const char*, const std::string&); +std::wstring operator+(const std::wstring&, const std::wstring&); +std::wstring operator+(const std::wstring&, const wchar_t*); +std::wstring operator+(const wchar_t*, const std::wstring&); + bool operator==(const std::string&, const std::string&); bool operator==(const std::string&, const char*); bool operator==(const char*, const std::string&); @@ -181,11 +201,11 @@ bool operator!=(const char*, const std::string_view&); size_t strlen(const char* str); -namespace literals { -namespace string_literals { +inline namespace literals { +inline namespace string_literals { string operator""s(const char *, size_t); } -namespace string_view_literals { +inline namespace string_view_literals { string_view operator""sv(const char *, size_t); } } diff --git a/clang-tools-extra/test/clang-tidy/checkers/abseil/string-find-str-contains.cpp b/clang-tools-extra/test/clang-tidy/checkers/abseil/string-find-str-contains.cpp index c5d1f178e48b0..ce7587caba072 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/abseil/string-find-str-contains.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/abseil/string-find-str-contains.cpp @@ -1,5 +1,10 @@ // RUN: %check_clang_tidy %s abseil-string-find-str-contains %t -- +// FIXME: Mocks use by-value find(basic_string s, ...) instead of the real +// find(const basic_string&, ...) signature. The checker's hasType(StringType) +// matcher doesn't match reference types, so find(const string&) overloads are +// never caught. + using size_t = decltype(sizeof(int)); namespace std { diff --git a/clang-tools-extra/test/clang-tidy/checkers/boost/use-to-string.cpp b/clang-tools-extra/test/clang-tidy/checkers/boost/use-to-string.cpp index f888c430e6883..815c254e09a86 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/boost/use-to-string.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/boost/use-to-string.cpp @@ -1,13 +1,5 @@ -// RUN: %check_clang_tidy %s boost-use-to-string %t - -namespace std { - -template <typename T> -class basic_string {}; - -using string = basic_string<char>; -using wstring = basic_string<wchar_t>; -} +// RUN: %check_clang_tidy %s boost-use-to-string %t -- -- -isystem %clang_tidy_headers +#include <string> namespace boost { template <typename T, typename V> diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp index eb044544d025e..e6da761aa9121 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp @@ -9,6 +9,7 @@ // RUN: {bugprone-dangling-handle.HandleClasses: \ // RUN: 'std::basic_string_view; ::llvm::StringRef;'}}" \ // RUN: -- -isystem %clang_tidy_headers +#include <string> #include <vector> namespace std { @@ -36,28 +37,6 @@ class map { value_type& operator[](Key&& key); }; -class basic_string_view; - -class basic_string { - public: - basic_string(); - basic_string(const char*); - - typedef basic_string_view str_view; - operator str_view() const noexcept; - - ~basic_string(); -}; - -typedef basic_string string; - -class basic_string_view { - public: - basic_string_view(const char*); -}; - -typedef basic_string_view string_view; - } // namespace std namespace llvm { diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters-prefixsuffixname.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters-prefixsuffixname.cpp index 00e54d0df690e..fdcc461c45936 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters-prefixsuffixname.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/easily-swappable-parameters-prefixsuffixname.cpp @@ -7,11 +7,9 @@ // RUN: bugprone-easily-swappable-parameters.ModelImplicitConversions: 0, \ // RUN: bugprone-easily-swappable-parameters.SuppressParametersUsedTogether: 0, \ // RUN: bugprone-easily-swappable-parameters.NamePrefixSuffixSilenceDissimilarityThreshold: 1 \ -// RUN: }}' -- +// RUN: }}' -- -isystem %clang_tidy_headers +#include <string> -namespace std { -struct string {}; -} // namespace std class Matrix {}; void test1(int Foo, int Bar) {} diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-container.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-container.cpp index b45183de895a2..694cabc0d0375 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-container.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-container.cpp @@ -1,24 +1,9 @@ -// RUN: %check_clang_tidy %s bugprone-sizeof-container %t -- -- -target x86_64-unknown-unknown +// RUN: %check_clang_tidy %s bugprone-sizeof-container %t -- -- -isystem %clang_tidy_headers -target x86_64-unknown-unknown +#include <string> +#include <vector> namespace std { -typedef unsigned int size_t; - -template <typename T> -struct basic_string { - size_t size() const; -}; - -template <typename T> -basic_string<T> operator+(const basic_string<T> &, const T *); - -typedef basic_string<char> string; - -template <typename T> -struct vector { - size_t size() const; -}; - // std::bitset<> is not a container. sizeof() is reasonable for it. template <size_t N> struct bitset { @@ -41,8 +26,6 @@ struct fake_container2 { } -using std::size_t; - #define ARRAYSIZE(a) \ ((sizeof(a) / sizeof(*(a))) / static_cast<size_t>(!(sizeof(a) % sizeof(*(a))))) @@ -50,7 +33,7 @@ using std::size_t; (((sizeof(a)) / (sizeof(*(a)))) / static_cast<size_t>(!((sizeof(a)) % (sizeof(*(a)))))) struct string { - std::size_t size() const; + size_t size() const; }; template<typename T> diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/string-integer-assignment.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/string-integer-assignment.cpp index e127788bf6ca6..f5a4b079fa074 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/string-integer-assignment.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/string-integer-assignment.cpp @@ -1,19 +1,7 @@ -// RUN: %check_clang_tidy %s bugprone-string-integer-assignment %t -- -- -fno-delayed-template-parsing +// RUN: %check_clang_tidy %s bugprone-string-integer-assignment %t -- -- -isystem %clang_tidy_headers -fno-delayed-template-parsing +#include <string> namespace std { -template<typename T> -struct basic_string { - basic_string& operator=(T); - basic_string& operator=(basic_string); - basic_string& operator+=(T); - basic_string& operator+=(basic_string); - const T &operator[](int i) const; - T &operator[](int i); -}; - -typedef basic_string<char> string; -typedef basic_string<wchar_t> wstring; - int tolower(int i); int toupper(int i); } diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nodiscard.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nodiscard.cpp index edd6ce00682d8..df17761c2e515 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nodiscard.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nodiscard.cpp @@ -1,10 +1,11 @@ // RUN: %check_clang_tidy -std=c++17-or-later %s modernize-use-nodiscard %t -- \ -// RUN: -config="{CheckOptions: {modernize-use-nodiscard.ReplacementString: 'NO_DISCARD'}}" +// RUN: -config="{CheckOptions: {modernize-use-nodiscard.ReplacementString: 'NO_DISCARD'}}" \ +// RUN: -- -isystem %clang_tidy_headers +#include <string> namespace std { template <class> class function; -class string {}; } namespace boost { diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-transform-lambdas-cxx14.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-transform-lambdas-cxx14.cpp index 278607e49713d..60762304d2fc8 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-transform-lambdas-cxx14.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-transform-lambdas-cxx14.cpp @@ -1,10 +1,7 @@ // RUN: %check_clang_tidy -std=c++14-or-later %s modernize-use-trailing-return-type %t -- -- -fno-delayed-template-parsing -isystem %clang_tidy_headers +#include <string> #include <vector> -namespace std { - class string {}; -} // namespace std - void test_lambda_positive() { auto l1 = [](auto x) { return x; }; // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use a trailing return type for this lambda [modernize-use-trailing-return-type] diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-transform-lambdas.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-transform-lambdas.cpp index d5307b7b61b31..d06048ae5ccf8 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-transform-lambdas.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-transform-lambdas.cpp @@ -10,12 +10,9 @@ // RUN: -config="{CheckOptions: {modernize-use-trailing-return-type.TransformLambdas: none, \ // RUN: modernize-use-trailing-return-type.TransformFunctions: true}}" \ // RUN: -- -fno-delayed-template-parsing -isystem %clang_tidy_headers +#include <string> #include <vector> -namespace std { - class string {}; -} // namespace std - void test_lambda_positive() { auto l01 = [] {}; // CHECK-MESSAGES-ALL: :[[@LINE-1]]:14: warning: use a trailing return type for this lambda [modernize-use-trailing-return-type] diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/faster-string-find.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/faster-string-find.cpp index 83824c62494e7..b8b5c1f752a62 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/faster-string-find.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/faster-string-find.cpp @@ -1,44 +1,9 @@ -// RUN: %check_clang_tidy %s performance-faster-string-find %t +// RUN: %check_clang_tidy %s performance-faster-string-find %t -- -- -isystem %clang_tidy_headers // RUN: %check_clang_tidy -check-suffix=CUSTOM %s performance-faster-string-find %t -- \ // RUN: -config="{CheckOptions: \ // RUN: {performance-faster-string-find.StringLikeClasses: \ -// RUN: '::llvm::StringRef;'}}" - -namespace std { -template <typename Char> -struct basic_string { - int find(const Char *, int = 0) const; - int find(const Char *, int, int) const; - int rfind(const Char *) const; - int find_first_of(const Char *) const; - int find_first_not_of(const Char *) const; - int find_last_of(const Char *) const; - int find_last_not_of(const Char *) const; - bool starts_with(const Char *) const; - bool ends_with(const Char *) const; - bool contains(const Char *) const; -}; - -typedef basic_string<char> string; -typedef basic_string<wchar_t> wstring; - -template <typename Char> -struct basic_string_view { - int find(const Char *, int = 0) const; - int find(const Char *, int, int) const; - int rfind(const Char *) const; - int find_first_of(const Char *) const; - int find_first_not_of(const Char *) const; - int find_last_of(const Char *) const; - int find_last_not_of(const Char *) const; - bool starts_with(const Char *) const; - bool ends_with(const Char *) const; - bool contains(const Char *) const; -}; - -typedef basic_string_view<char> string_view; -typedef basic_string_view<wchar_t> wstring_view; -} // namespace std +// RUN: '::llvm::StringRef;'}}" -- -isystem %clang_tidy_headers +#include <string> namespace llvm { struct StringRef { diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/inefficient-string-concatenation.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/inefficient-string-concatenation.cpp index a1edf5fae2f9e..6a6d5c27916a9 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/inefficient-string-concatenation.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/inefficient-string-concatenation.cpp @@ -1,17 +1,5 @@ -// RUN: %check_clang_tidy %s performance-inefficient-string-concatenation %t - -namespace std { -template <typename T> -class basic_string { -public: - basic_string() {} - ~basic_string() {} - basic_string<T> *operator+=(const basic_string<T> &); - friend basic_string<T> operator+(const basic_string<T> &, const basic_string<T> &); -}; -typedef basic_string<char> string; -typedef basic_string<wchar_t> wstring; -} +// RUN: %check_clang_tidy %s performance-inefficient-string-concatenation %t -- -- -isystem %clang_tidy_headers +#include <string> void f(std::string) {} std::string g(std::string); diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static-deducing-this.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static-deducing-this.cpp index 7974301aecce0..985701ac78b35 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static-deducing-this.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static-deducing-this.cpp @@ -1,7 +1,7 @@ -// RUN: %check_clang_tidy -std=c++23-or-later %s readability-convert-member-functions-to-static %t +// RUN: %check_clang_tidy -std=c++23-or-later %s readability-convert-member-functions-to-static %t -- -- -isystem %clang_tidy_headers +#include <string> namespace std{ - class string {}; void println(const char *format, const std::string &str) {} } diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return.cpp index 220c7ba19fed0..2847248b2259b 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/else-after-return.cpp @@ -1,11 +1,5 @@ -// RUN: %check_clang_tidy %s readability-else-after-return %t -- -- -fexceptions -std=c++17 - -namespace std { -struct string { - string(const char *); - ~string(); -}; -} // namespace std +// RUN: %check_clang_tidy %s readability-else-after-return %t -- -- -isystem %clang_tidy_headers -fexceptions -std=c++17 +#include <string> struct my_exception { my_exception(const std::string &s); diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/isolate-declaration-cxx17.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/isolate-declaration-cxx17.cpp index 37cdf109a5d89..fd06a18ed6e0a 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/isolate-declaration-cxx17.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/isolate-declaration-cxx17.cpp @@ -30,20 +30,7 @@ struct SomeClass { SomeClass(int value); }; -namespace std { - -class string { -public: - string() = default; - string(const char *) {} -}; - -namespace string_literals { -string operator""s(const char *, decltype(sizeof(int))) { - return string(); -} -} // namespace string_literals -} // namespace std +#include <string> namespace Types { typedef int MyType; diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-init.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-init.cpp index 1e828488dc153..93334486e9da9 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-init.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-init.cpp @@ -2,37 +2,8 @@ // RUN: -config="{CheckOptions: \ // RUN: {readability-redundant-string-init.StringNames: \ // RUN: '::std::basic_string;::std::basic_string_view;our::TestString'} \ -// RUN: }" - -namespace std { -template <typename T> -class allocator {}; -template <typename T> -class char_traits {}; -template <typename C, typename T = std::char_traits<C>, typename A = std::allocator<C>> -struct basic_string { - basic_string(); - basic_string(const basic_string&); - basic_string(const C *, const A &a = A()); - ~basic_string(); -}; -typedef basic_string<char> string; -typedef basic_string<wchar_t> wstring; - -template <typename C, typename T = std::char_traits<C>, typename A = std::allocator<C>> -struct basic_string_view { - using size_type = decltype(sizeof(0)); - - basic_string_view(); - basic_string_view(const basic_string_view &); - basic_string_view(const C *, size_type); - basic_string_view(const C *); - template <class It, class End> - basic_string_view(It, End); -}; -typedef basic_string_view<char> string_view; -typedef basic_string_view<wchar_t> wstring_view; -} +// RUN: }" -- -isystem %clang_tidy_headers +#include <string> void f() { std::string a = ""; diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/simplify-subscript-expr.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/simplify-subscript-expr.cpp index e5ad6f96def7d..a04521a7edd72 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/simplify-subscript-expr.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/simplify-subscript-expr.cpp @@ -1,40 +1,9 @@ // RUN: %check_clang_tidy %s readability-simplify-subscript-expr %t \ // RUN: -config="{CheckOptions: \ // RUN: {readability-simplify-subscript-expr.Types: \ -// RUN: '::std::basic_string;::std::basic_string_view;MyVector'}}" -- - -namespace std { - -template <class T> -class basic_string { - public: - using size_type = unsigned; - using value_type = T; - using ... [truncated] `````````` </details> https://github.com/llvm/llvm-project/pull/183996 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
