https://github.com/vbvictor created https://github.com/llvm/llvm-project/pull/183963
In new tests we should encourage to use these "source of truth" files if possible. >From cc8c4aa354824f768859b8415ee4b230bb1a80d4 Mon Sep 17 00:00:00 2001 From: Victor Baranov <[email protected]> Date: Sun, 1 Mar 2026 01:28:28 +0300 Subject: [PATCH 1/2] [clang-tidy][NFC] Use singe mock vector header in tests --- .../Headers/initializer_list} | 24 ++--- .../clang-tidy/checkers/Inputs/Headers/memory | 11 +++ .../clang-tidy/checkers/Inputs/Headers/string | 5 +- .../clang-tidy/checkers/Inputs/Headers/vector | 91 +++++++++++++++++++ .../boost/Inputs/use-ranges/fake_std.h | 24 +---- .../checkers/boost/use-ranges-pipe.cpp | 4 +- .../clang-tidy/checkers/boost/use-ranges.cpp | 4 +- .../checkers/bugprone/argument-comment.cpp | 8 +- .../checkers/bugprone/dangling-handle.cpp | 23 +---- .../bugprone/unchecked-optional-access.cpp | 12 +-- .../checkers/bugprone/unused-return-value.cpp | 11 +-- .../clang-tidy/checkers/llvm/use-ranges.cpp | 16 +--- .../modernize/Inputs/use-ranges/fake_std.h | 23 +---- .../modernize/make-unique-default-init.cpp | 4 +- .../checkers/modernize/make-unique.cpp | 4 +- .../modernize/replace-random-shuffle.cpp | 10 +- .../modernize/return-braced-init-list.cpp | 44 +-------- .../checkers/modernize/shrink-to-fit.cpp | 7 +- ...e-emplace-ignore-implicit-constructors.cpp | 29 +----- .../checkers/modernize/use-ranges-pipe.cpp | 4 +- .../checkers/modernize/use-ranges.cpp | 4 +- ...ng-return-type-transform-lambdas-cxx14.cpp | 6 +- ...trailing-return-type-transform-lambdas.cpp | 10 +- .../inefficient-vector-operation.cpp | 46 +--------- .../readability/container-data-pointer.cpp | 14 +-- .../readability/isolate-declaration-cxx17.cpp | 12 +-- .../readability/qualified-auto-cxx20.cpp | 16 +--- .../checkers/readability/qualified-auto.cpp | 17 +--- .../readability/redundant-smartptr-get.cpp | 20 +--- 29 files changed, 175 insertions(+), 328 deletions(-) rename clang-tools-extra/test/clang-tidy/checkers/{modernize/Inputs/smart-ptr/initializer_list.h => Inputs/Headers/initializer_list} (67%) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/memory create mode 100644 clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/vector diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/initializer_list.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/initializer_list similarity index 67% rename from clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/initializer_list.h rename to clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/initializer_list index 28592cf8f70b1..bccea047d3e63 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/smart-ptr/initializer_list.h +++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/initializer_list @@ -1,32 +1,34 @@ +#ifndef _INITIALIZER_LIST_ +#define _INITIALIZER_LIST_ + +// For size_t +#include "string.h" +#include "memory" + namespace std { -typedef decltype(sizeof(int)) size_t; -template <class _E> class initializer_list { +template <class _E> +class initializer_list { const _E *__begin_; size_t __size_; - initializer_list(const _E *__b, size_t __s) : __begin_(__b), __size_(__s) {} + initializer_list(const _E *__b, size_t __s) + : __begin_(__b), __size_(__s) {} public: typedef _E value_type; typedef const _E &reference; typedef const _E &const_reference; typedef size_t size_type; - typedef const _E *iterator; typedef const _E *const_iterator; initializer_list() : __begin_(nullptr), __size_(0) {} - size_t size() const { return __size_; } const _E *begin() const { return __begin_; } const _E *end() const { return __begin_ + __size_; } }; -template <class _E> -class vector { - public: - vector(initializer_list<_E> init); - ~vector(); -}; } // namespace std + +#endif // _INITIALIZER_LIST_ diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/memory b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/memory new file mode 100644 index 0000000000000..e1dd37d9661f9 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/memory @@ -0,0 +1,11 @@ +#ifndef _ALLOCATOR_ +#define _ALLOCATOR_ + +namespace std { + +template <typename T> +class allocator {}; + +} // namespace std + +#endif // _ALLOCATOR_ 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 7de709d07f2df..fc197d0afa714 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string +++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string @@ -2,14 +2,13 @@ #define _STRING_ // For size_t -#include <string.h> +#include "string.h" +#include "memory" typedef unsigned __INT16_TYPE__ char16; typedef unsigned __INT32_TYPE__ char32; namespace std { -template <typename T> -class allocator {}; template <typename T> class char_traits {}; diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/vector b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/vector new file mode 100644 index 0000000000000..32eebb9387172 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/vector @@ -0,0 +1,91 @@ +#ifndef _VECTOR_ +#define _VECTOR_ + +#include "initializer_list" +#include "memory" + +namespace std { + +template <typename T, typename A = allocator<T>> +class vector { +public: + typedef T value_type; + typedef size_t size_type; + typedef T *iterator; + typedef const T *const_iterator; + typedef T *reverse_iterator; + typedef const T *const_reverse_iterator; + + vector(); + vector(size_type count); + vector(size_type count, const T &value, const A &alloc = A()); + vector(initializer_list<T>, const A &alloc = A()); + vector(const vector &other); + vector(vector &&other); + ~vector(); + + vector &operator=(const vector &other); + vector &operator=(vector &&other); + vector &operator=(initializer_list<T>); + + void push_back(const T &value); + void push_back(T &&value); + + template <typename... Args> + void emplace_back(Args &&...args); + + template <typename... Args> + iterator emplace(const_iterator pos, Args &&...args); + + T &operator[](size_type pos); + const T &operator[](size_type pos) const; + + T &front(); + T &back(); + T *data(); + const T *data() const; + + iterator begin(); + iterator end(); + const_iterator begin() const; + const_iterator end() const; + const_iterator cbegin() const; + const_iterator cend() const; + + reverse_iterator rbegin(); + reverse_iterator rend(); + const_reverse_iterator rbegin() const; + const_reverse_iterator rend() const; + const_reverse_iterator crbegin() const; + const_reverse_iterator crend() const; + + bool empty() const; + size_type size() const; + + void clear(); + void reserve(size_type new_cap); + void resize(size_type count); + void resize(size_type count, const T &value); + + void assign(size_type count, const T &value); + + iterator insert(const_iterator pos, const T &value); + iterator insert(const_iterator pos, T &&value); + iterator insert(const_iterator pos, size_type count, const T &value); + + iterator erase(const_iterator pos); + iterator erase(const_iterator first, const_iterator last); + + void swap(vector &other); + void shrink_to_fit(); +}; + +template <typename T, typename A> +bool operator==(const vector<T, A> &, const vector<T, A> &); + +template <typename T, typename A> +bool operator!=(const vector<T, A> &, const vector<T, A> &); + +} // namespace std + +#endif // _VECTOR_ diff --git a/clang-tools-extra/test/clang-tidy/checkers/boost/Inputs/use-ranges/fake_std.h b/clang-tools-extra/test/clang-tidy/checkers/boost/Inputs/use-ranges/fake_std.h index 7c3e39d6000d2..26842c4dbddcb 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/boost/Inputs/use-ranges/fake_std.h +++ b/clang-tools-extra/test/clang-tidy/checkers/boost/Inputs/use-ranges/fake_std.h @@ -1,27 +1,9 @@ #ifndef USE_RANGES_FAKE_STD_H #define USE_RANGES_FAKE_STD_H -namespace std { -template <typename T> class vector { -public: - using iterator = T *; - using const_iterator = const T *; - using reverse_iterator = T*; - using reverse_const_iterator = const T*; - - constexpr const_iterator begin() const; - constexpr const_iterator end() const; - constexpr const_iterator cbegin() const; - constexpr const_iterator cend() const; - constexpr iterator begin(); - constexpr iterator end(); - constexpr reverse_const_iterator rbegin() const; - constexpr reverse_const_iterator rend() const; - constexpr reverse_const_iterator crbegin() const; - constexpr reverse_const_iterator crend() const; - constexpr reverse_iterator rbegin(); - constexpr reverse_iterator rend(); -}; +#include <vector> + +namespace std { template <typename Container> constexpr auto begin(const Container &Cont) { return Cont.begin(); diff --git a/clang-tools-extra/test/clang-tidy/checkers/boost/use-ranges-pipe.cpp b/clang-tools-extra/test/clang-tidy/checkers/boost/use-ranges-pipe.cpp index c0ce374840098..2b32429a77a60 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/boost/use-ranges-pipe.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/boost/use-ranges-pipe.cpp @@ -1,7 +1,7 @@ // RUN: %check_clang_tidy -std=c++14 %s boost-use-ranges %t -check-suffixes=,PIPE \ // RUN: -config="{CheckOptions: { \ -// RUN: boost-use-ranges.UseReversePipe: true }}" -- -I %S/Inputs/use-ranges/ -// RUN: %check_clang_tidy -std=c++14 %s boost-use-ranges %t -check-suffixes=,NOPIPE -- -I %S/Inputs/use-ranges/ +// RUN: boost-use-ranges.UseReversePipe: true }}" -- -isystem %clang_tidy_headers -I %S/Inputs/use-ranges/ +// RUN: %check_clang_tidy -std=c++14 %s boost-use-ranges %t -check-suffixes=,NOPIPE -- -isystem %clang_tidy_headers -I %S/Inputs/use-ranges/ // CHECK-FIXES: #include <boost/algorithm/cxx11/is_sorted.hpp> // CHECK-FIXES: #include <boost/range/adaptor/reversed.hpp> diff --git a/clang-tools-extra/test/clang-tidy/checkers/boost/use-ranges.cpp b/clang-tools-extra/test/clang-tidy/checkers/boost/use-ranges.cpp index 06e70267da83a..a11915e26269f 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/boost/use-ranges.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/boost/use-ranges.cpp @@ -1,5 +1,5 @@ -// RUN: %check_clang_tidy -std=c++14 %s boost-use-ranges %t -- -- -I %S/Inputs/use-ranges/ -// RUN: %check_clang_tidy -std=c++17 %s boost-use-ranges %t -check-suffixes=,CPP17 -- -I %S/Inputs/use-ranges/ +// RUN: %check_clang_tidy -std=c++14 %s boost-use-ranges %t -- -- -isystem %clang_tidy_headers -I %S/Inputs/use-ranges/ +// RUN: %check_clang_tidy -std=c++17 %s boost-use-ranges %t -check-suffixes=,CPP17 -- -isystem %clang_tidy_headers -I %S/Inputs/use-ranges/ // CHECK-FIXES: #include <boost/range/algorithm/find.hpp> // CHECK-FIXES: #include <boost/range/algorithm/reverse.hpp> diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment.cpp index 28b19ccdcf450..5576bc5541d60 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/argument-comment.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy %s bugprone-argument-comment %t -- -- -I %S/Inputs/argument-comment +// RUN: %check_clang_tidy %s bugprone-argument-comment %t -- -- -I %S/Inputs/argument-comment -isystem %clang_tidy_headers // FIXME: clang-tidy should provide a -verify mode to make writing these checks // easier and more accurate. @@ -117,12 +117,8 @@ void g() { f6(/*xxy=*/0, 0); } } +#include <vector> namespace std { -template <typename T> -class vector { -public: - void assign(int __n, const T &__val); -}; template<typename T> void swap(T& __a, T& __b); } // namespace std 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 96c812617038a..eb044544d025e 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 @@ -1,31 +1,18 @@ // RUN: %check_clang_tidy -std=c++11,c++14 -check-suffix=,CXX14 %s bugprone-dangling-handle %t -- \ // RUN: -config="{CheckOptions: \ // RUN: {bugprone-dangling-handle.HandleClasses: \ -// RUN: 'std::basic_string_view; ::llvm::StringRef;'}}" +// RUN: 'std::basic_string_view; ::llvm::StringRef;'}}" \ +// RUN: -- -isystem %clang_tidy_headers // RUN: %check_clang_tidy -std=c++17-or-later -check-suffix=,CXX17 %s bugprone-dangling-handle %t -- \ // RUN: -config="{CheckOptions: \ // RUN: {bugprone-dangling-handle.HandleClasses: \ -// RUN: 'std::basic_string_view; ::llvm::StringRef;'}}" +// RUN: 'std::basic_string_view; ::llvm::StringRef;'}}" \ +// RUN: -- -isystem %clang_tidy_headers +#include <vector> namespace std { -template <typename T> -class vector { - public: - using const_iterator = const T*; - using iterator = T*; - using size_type = int; - - void assign(size_type count, const T& value); - iterator insert(const_iterator pos, const T& value); - iterator insert(const_iterator pos, T&& value); - iterator insert(const_iterator pos, size_type count, const T& value); - void push_back(const T&); - void push_back(T&&); - void resize(size_type count, const T& value); -}; - template <typename, typename> class pair {}; diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp index 984156c028c00..4831374bda6db 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy %s bugprone-unchecked-optional-access %t -- -- -I %S/Inputs/unchecked-optional-access +// RUN: %check_clang_tidy %s bugprone-unchecked-optional-access %t -- -- -I %S/Inputs/unchecked-optional-access -isystem %clang_tidy_headers #include "absl/types/optional.h" #include "folly/types/Optional.h" @@ -351,15 +351,7 @@ void std_forward_rvalue_ref_safe(absl::optional<int>&& opt) { std::forward<absl::optional<int>>(opt).value(); } -namespace std { - -template <typename T> class vector { -public: - T &operator[](unsigned long index); - bool empty(); -}; - -} // namespace std +#include <vector> struct S { absl::optional<float> x; diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp index e784c9b85172c..938f12a582fbe 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp @@ -1,5 +1,6 @@ // RUN: %check_clang_tidy %s bugprone-unused-return-value %t -- \ -// RUN: --config="{CheckOptions: {bugprone-unused-return-value.AllowCastToVoid: true}}" -- -fexceptions +// RUN: --config="{CheckOptions: {bugprone-unused-return-value.AllowCastToVoid: true}}" -- -fexceptions -isystem %clang_tidy_headers +#include <vector> namespace std { @@ -41,9 +42,6 @@ struct unique_ptr { template <typename T> struct char_traits; -template <typename T> -struct allocator; - template <typename CharT, typename Traits = char_traits<CharT>, typename Allocator = allocator<CharT>> @@ -53,11 +51,6 @@ struct basic_string { typedef basic_string<char> string; -template <typename T, typename Allocator = std::allocator<T>> -struct vector { - bool empty() const noexcept; -}; - class error_code { }; diff --git a/clang-tools-extra/test/clang-tidy/checkers/llvm/use-ranges.cpp b/clang-tools-extra/test/clang-tidy/checkers/llvm/use-ranges.cpp index 415593ae16a53..7be84f59b5a8c 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/llvm/use-ranges.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/llvm/use-ranges.cpp @@ -1,23 +1,11 @@ -// RUN: %check_clang_tidy %s llvm-use-ranges %t +// RUN: %check_clang_tidy %s llvm-use-ranges %t -- -- -isystem %clang_tidy_headers +#include <vector> // Test that the header is included // CHECK-FIXES: #include "llvm/ADT/STLExtras.h" namespace std { -template <typename T> class vector { -public: - using iterator = T *; - using const_iterator = const T *; - - iterator begin(); - iterator end(); - const_iterator begin() const; - const_iterator end() const; - const_iterator cbegin() const; - const_iterator cend() const; -}; - template <typename T> T* begin(T (&arr)[5]); template <typename T> T* end(T (&arr)[5]); diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/use-ranges/fake_std.h b/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/use-ranges/fake_std.h index 69ac9954f4afa..f417dd32d8946 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/use-ranges/fake_std.h +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/use-ranges/fake_std.h @@ -1,28 +1,9 @@ #ifndef USE_RANGES_FAKE_STD_H #define USE_RANGES_FAKE_STD_H -namespace std { +#include <vector> -template <typename T> class vector { -public: - using iterator = T *; - using const_iterator = const T *; - using reverse_iterator = T *; - using reverse_const_iterator = const T *; - - constexpr const_iterator begin() const; - constexpr const_iterator end() const; - constexpr const_iterator cbegin() const; - constexpr const_iterator cend() const; - constexpr iterator begin(); - constexpr iterator end(); - constexpr reverse_const_iterator rbegin() const; - constexpr reverse_const_iterator rend() const; - constexpr reverse_const_iterator crbegin() const; - constexpr reverse_const_iterator crend() const; - constexpr reverse_iterator rbegin(); - constexpr reverse_iterator rend(); -}; +namespace std { template <typename Container> constexpr auto begin(const Container &Cont) { return Cont.begin(); diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-default-init.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-default-init.cpp index 7b96d014c4ed3..4556cdf445d29 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-default-init.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique-default-init.cpp @@ -3,10 +3,10 @@ // RUN: {modernize-make-unique.IgnoreDefaultInitialization: \ // RUN: 'false'}} \ // RUN: }" \ -// RUN: -- -I %S/Inputs/smart-ptr +// RUN: -- -I %S/Inputs/smart-ptr -isystem %clang_tidy_headers -#include "initializer_list.h" #include "unique_ptr.h" +#include <vector> // CHECK-FIXES: #include <memory> void basic() { diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp index bcdf4fb4e3756..45d9d15315e95 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp @@ -1,7 +1,7 @@ -// RUN: %check_clang_tidy -std=c++14-or-later %s modernize-make-unique %t -- -- -I %S/Inputs/smart-ptr +// RUN: %check_clang_tidy -std=c++14-or-later %s modernize-make-unique %t -- -- -I %S/Inputs/smart-ptr -isystem %clang_tidy_headers #include "unique_ptr.h" -#include "initializer_list.h" +#include <vector> // CHECK-FIXES: #include <memory> struct Base { diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/replace-random-shuffle.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/replace-random-shuffle.cpp index f96a60b377873..5a9c8560da8ce 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/replace-random-shuffle.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/replace-random-shuffle.cpp @@ -1,4 +1,5 @@ -// RUN: %check_clang_tidy %s modernize-replace-random-shuffle %t +// RUN: %check_clang_tidy %s modernize-replace-random-shuffle %t -- -- -isystem %clang_tidy_headers +#include <vector> //CHECK-FIXES: #include <random> @@ -8,13 +9,6 @@ template <typename T> struct vec_iterator { vec_iterator operator++(int); }; -template <typename T> struct vector { - typedef vec_iterator<T> iterator; - - iterator begin(); - iterator end(); -}; - template <typename FwIt> void random_shuffle(FwIt begin, FwIt end); diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/return-braced-init-list.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/return-braced-init-list.cpp index ae33d25d49152..42c01202055aa 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/return-braced-init-list.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/return-braced-init-list.cpp @@ -1,45 +1,5 @@ -// RUN: %check_clang_tidy -std=c++11-or-later %s modernize-return-braced-init-list %t - -namespace std { -typedef decltype(sizeof(int)) size_t; - -// libc++'s implementation -template <class _E> -class initializer_list { - const _E *__begin_; - size_t __size_; - - initializer_list(const _E *__b, size_t __s) - : __begin_(__b), - __size_(__s) {} - -public: - typedef _E value_type; - typedef const _E &reference; - typedef const _E &const_reference; - typedef size_t size_type; - - typedef const _E *iterator; - typedef const _E *const_iterator; - - initializer_list() : __begin_(nullptr), __size_(0) {} - - size_t size() const { return __size_; } - const _E *begin() const { return __begin_; } - const _E *end() const { return __begin_ + __size_; } -}; - -template <typename T> -struct allocator {}; - -template <typename T, typename Allocator = ::std::allocator<T>> -class vector { -public: - vector(T); - vector(size_t, T, const Allocator &alloc = Allocator()); - vector(std::initializer_list<T>); -}; -} // namespace std +// RUN: %check_clang_tidy -std=c++11-or-later %s modernize-return-braced-init-list %t -- -- -isystem %clang_tidy_headers +#include <vector> class Bar {}; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/shrink-to-fit.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/shrink-to-fit.cpp index a3754e6822ac8..fc27719bab12b 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/shrink-to-fit.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/shrink-to-fit.cpp @@ -1,8 +1,5 @@ -// RUN: %check_clang_tidy %s modernize-shrink-to-fit %t - -namespace std { -template <typename T> struct vector { void swap(vector &other); }; -} +// RUN: %check_clang_tidy %s modernize-shrink-to-fit %t -- -- -isystem %clang_tidy_headers +#include <vector> void f() { std::vector<int> v; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace-ignore-implicit-constructors.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace-ignore-implicit-constructors.cpp index 150e3ac6494e3..5202eceb57fcd 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace-ignore-implicit-constructors.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace-ignore-implicit-constructors.cpp @@ -1,32 +1,9 @@ // RUN: %check_clang_tidy %s modernize-use-emplace %t -- \ // RUN: -config="{CheckOptions: \ // RUN: {modernize-use-emplace.IgnoreImplicitConstructors: \ -// RUN: true}}" - -namespace std { -template <typename E> -class initializer_list -{ -public: - const E *a, *b; - initializer_list() noexcept {} -}; - -template <typename T> -class vector { -public: - vector() = default; - vector(initializer_list<T>) {} - - void push_back(const T &) {} - void push_back(T &&) {} - - template <typename... Args> - void emplace_back(Args &&... args){}; - ~vector(); -}; - -} // namespace std +// RUN: true}}" \ +// RUN: -- -isystem %clang_tidy_headers +#include <vector> void testInts() { std::vector<int> v; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges-pipe.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges-pipe.cpp index c084bcddaabb8..9a78bd5958814 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges-pipe.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges-pipe.cpp @@ -1,7 +1,7 @@ // RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -check-suffixes=,PIPE \ // RUN: -config="{CheckOptions: { \ -// RUN: modernize-use-ranges.UseReversePipe: true }}" -- -I %S/Inputs/use-ranges/ -// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -check-suffixes=,NOPIPE -- -I %S/Inputs/use-ranges/ +// RUN: modernize-use-ranges.UseReversePipe: true }}" -- -isystem %clang_tidy_headers -I %S/Inputs/use-ranges/ +// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -check-suffixes=,NOPIPE -- -isystem %clang_tidy_headers -I %S/Inputs/use-ranges/ // CHECK-FIXES: #include <algorithm> // CHECK-FIXES: #include <ranges> diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp index 6b196a8f42189..c1338a7e9b640 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp @@ -1,5 +1,5 @@ -// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -I %S/Inputs/ -// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t -check-suffixes=,CPP23 -- -I %S/Inputs/ +// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -isystem %clang_tidy_headers -I %S/Inputs/ +// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t -check-suffixes=,CPP23 -- -isystem %clang_tidy_headers -I %S/Inputs/ // Example: ./check_clang_tidy.py -std=c++20 checkers/modernize/use-ranges.cpp modernize-use-ranges temp.txt -- -- -I ~/llvm-project/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/ // CHECK-FIXES: #include <algorithm> 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 cd88c84629ce4..278607e49713d 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,9 +1,7 @@ -// RUN: %check_clang_tidy -std=c++14-or-later %s modernize-use-trailing-return-type %t -- -- -fno-delayed-template-parsing +// 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 <vector> namespace std { - template <typename T> - class vector {}; - class string {}; } // namespace std 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 3d2d94ee56a76..d5307b7b61b31 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 @@ -1,20 +1,18 @@ // RUN: %check_clang_tidy -check-suffix=ALL -std=c++11-or-later %s modernize-use-trailing-return-type %t --\ // RUN: -config="{CheckOptions: {modernize-use-trailing-return-type.TransformLambdas: all, \ // RUN: modernize-use-trailing-return-type.TransformFunctions: false}}" \ -// RUN: -- -fno-delayed-template-parsing +// RUN: -- -fno-delayed-template-parsing -isystem %clang_tidy_headers // RUN: %check_clang_tidy -check-suffix=NOAUTO -std=c++11-or-later %s modernize-use-trailing-return-type %t --\ // RUN: -config="{CheckOptions: {modernize-use-trailing-return-type.TransformLambdas: all_except_auto, \ // RUN: modernize-use-trailing-return-type.TransformFunctions: false}}" \ -// RUN: -- -fno-delayed-template-parsing +// RUN: -- -fno-delayed-template-parsing -isystem %clang_tidy_headers // RUN: %check_clang_tidy -check-suffix=NONE -std=c++11-or-later %s modernize-use-trailing-return-type %t --\ // RUN: -config="{CheckOptions: {modernize-use-trailing-return-type.TransformLambdas: none, \ // RUN: modernize-use-trailing-return-type.TransformFunctions: true}}" \ -// RUN: -- -fno-delayed-template-parsing +// RUN: -- -fno-delayed-template-parsing -isystem %clang_tidy_headers +#include <vector> namespace std { - template <typename T> - class vector {}; - class string {}; } // namespace std diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/inefficient-vector-operation.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/inefficient-vector-operation.cpp index e1e25d76d4909..00582845bbcff 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/inefficient-vector-operation.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/inefficient-vector-operation.cpp @@ -1,58 +1,18 @@ // RUN: %check_clang_tidy %s performance-inefficient-vector-operation %t -- \ // RUN: -format-style=llvm \ // RUN: -config='{CheckOptions: \ -// RUN: {performance-inefficient-vector-operation.EnableProto: true}}' +// RUN: {performance-inefficient-vector-operation.EnableProto: true}}' \ +// RUN: -- -isystem %clang_tidy_headers +#include <vector> namespace std { typedef decltype(sizeof 0) size_t; -template<class E> class initializer_list { -public: - using value_type = E; - using reference = E&; - using const_reference = const E&; - using size_type = size_t; - using iterator = const E*; - using const_iterator = const E*; - iterator p; - size_t sz; - initializer_list(); - size_t size() const; // number of elements - const E* begin() const; // first element - const E* end() const; // one past the last element -}; - // initializer list range access template<class E> const E* begin(initializer_list<E> il); template<class E> const E* end(initializer_list<E> il); -template <class T> -class vector { - public: - typedef T* iterator; - typedef const T* const_iterator; - typedef T& reference; - typedef const T& const_reference; - typedef size_t size_type; - - explicit vector(); - explicit vector(size_type n); - - void push_back(const T& val); - - template <class... Args> void emplace_back(Args &&... args); - - void reserve(size_t n); - void resize(size_t n); - - size_t size() const; - const_reference operator[] (size_type) const; - reference operator[] (size_type); - - const_iterator begin() const; - const_iterator end() const; -}; } // namespace std class Foo { diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp index 2ed1e939d71d4..004e429e53e6f 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp @@ -2,23 +2,11 @@ // RUN: %check_clang_tidy -check-suffixes=,WITH-CONFIG %s readability-container-data-pointer %t -- -config="{CheckOptions: {readability-container-data-pointer.IgnoredContainers: '::std::basic_string'}}" -- -isystem %clang_tidy_headers -fno-delayed-template-parsing #include <string> +#include <vector> typedef __SIZE_TYPE__ size_t; namespace std { -template <typename T> -struct vector { - using size_type = size_t; - - vector(); - explicit vector(size_type); - - T *data(); - const T *data() const; - - T &operator[](size_type); - const T &operator[](size_type) const; -}; template <typename T> struct is_integral; 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 a811db1879ecb..37cdf109a5d89 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 @@ -1,4 +1,5 @@ -// RUN: %check_clang_tidy -std=c++17-or-later %s readability-isolate-declaration %t +// RUN: %check_clang_tidy -std=c++17-or-later %s readability-isolate-declaration %t -- -- -isystem %clang_tidy_headers +#include <vector> template <typename T1, typename T2> struct pair { @@ -30,15 +31,6 @@ struct SomeClass { }; namespace std { -template <typename T> -class initializer_list { const T *a, *b; }; - -template <typename T> -class vector { -public: - vector() = default; - vector(initializer_list<T> init) {} -}; class string { public: diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/qualified-auto-cxx20.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/qualified-auto-cxx20.cpp index fea003476d733..aa58236c82139 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/qualified-auto-cxx20.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/qualified-auto-cxx20.cpp @@ -1,17 +1,5 @@ -// RUN: %check_clang_tidy %s readability-qualified-auto %t -- -- -std=c++20 -namespace std { -template <typename T> -class vector { // dummy impl - T _data[1]; - -public: - T *begin() { return _data; } - const T *begin() const { return _data; } - T *end() { return &_data[1]; } - const T *end() const { return &_data[1]; } - unsigned size() const { return 0; } -}; -} // namespace std +// RUN: %check_clang_tidy %s readability-qualified-auto %t -- -- -std=c++20 -isystem %clang_tidy_headers +#include <vector> std::vector<int> *getVec(); const std::vector<int> *getCVec(); diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/qualified-auto.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/qualified-auto.cpp index ffcf84ef77333..2f23e10e10f7d 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/qualified-auto.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/qualified-auto.cpp @@ -1,12 +1,12 @@ // RUN: %check_clang_tidy %s readability-qualified-auto %t \ // RUN: -config='{CheckOptions: { \ // RUN: readability-qualified-auto.AllowedTypes: "[iI]terator$;my::ns::Ignored1;std::array<.*>::Ignored2;MyIgnoredPtr" \ -// RUN: }}' +// RUN: }}' -- -isystem %clang_tidy_headers // RUN: %check_clang_tidy %s readability-qualified-auto %t \ // RUN: -config='{CheckOptions: { \ // RUN: readability-qualified-auto.AllowedTypes: "[iI]terator$;my::ns::Ignored1;std::array<.*>::Ignored2;MyIgnoredPtr", \ // RUN: readability-qualified-auto.IgnoreAliasing: false \ -// RUN: }}' -check-suffix=ALIAS -- +// RUN: }}' -check-suffix=ALIAS -- -isystem %clang_tidy_headers namespace typedefs { typedef int *MyPtr; @@ -179,18 +179,7 @@ void macroTest() { #undef _CONST } -namespace std { -template <typename T> -class vector { // dummy impl - T _data[1]; - -public: - T *begin() { return _data; } - const T *begin() const { return _data; } - T *end() { return &_data[1]; } - const T *end() const { return &_data[1]; } -}; -} // namespace std +#include <vector> void change(int &); void observe(const int &); diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get.cpp index 42e948fcb2a7f..4a840999cc654 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get.cpp @@ -1,4 +1,5 @@ -// RUN: %check_clang_tidy %s readability-redundant-smartptr-get %t +// RUN: %check_clang_tidy %s readability-redundant-smartptr-get %t -- -- -isystem %clang_tidy_headers +#include <vector> #define NULL __null @@ -34,23 +35,6 @@ struct shared_ptr<T[]> { explicit operator bool() const noexcept; }; -template <typename T> -struct vector { - vector(); - bool operator==(const vector<T>& other) const; - bool operator!=(const vector<T>& other) const; - unsigned long size() const; - bool empty() const; - - using iterator = T*; - - iterator begin(); - iterator end(); - - T* data; - unsigned long sz; -}; - } // namespace std struct Bar { >From ed05a8ba080148f01627ce0ac8d4e3daad68fe59 Mon Sep 17 00:00:00 2001 From: Victor Baranov <[email protected]> Date: Sun, 1 Mar 2026 01:31:07 +0300 Subject: [PATCH 2/2] allocator -> memory --- .../test/clang-tidy/checkers/Inputs/Headers/memory | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/memory b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/memory index e1dd37d9661f9..2ec18dbec18f4 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/memory +++ b/clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/memory @@ -1,5 +1,5 @@ -#ifndef _ALLOCATOR_ -#define _ALLOCATOR_ +#ifndef _MEMORY_ +#define _MEMORY_ namespace std { @@ -8,4 +8,4 @@ class allocator {}; } // namespace std -#endif // _ALLOCATOR_ +#endif // _MEMORY_ _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
