diff --git a/.clang-tidy b/.clang-tidy index 576a36fc9bf92..200ba9a2a3516 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -49,7 +49,7 @@ modernize-*, performance-*, readability-container-size-empty, ' -HeaderFilterRegex: '^(c10/(?!test)|torch/csrc/).*$' +HeaderFilterRegex: '^(c10/|torch/csrc/).*$' AnalyzeTemporaryDtors: false WarningsAsErrors: '*' ... diff --git a/.lintrunner.toml b/.lintrunner.toml index 926101d839ab3..d2b65dad84f91 100644 --- a/.lintrunner.toml +++ b/.lintrunner.toml @@ -262,7 +262,6 @@ exclude_patterns = [ '**/*pb.h', '**/*CUDA*', '**/cuda/*pp', - 'c10/test/**', 'third_party/**/*', 'torch/csrc/api/**', 'torch/csrc/autograd/functions/**', diff --git a/c10/test/core/impl/cow_test.cpp b/c10/test/core/impl/cow_test.cpp index 146acad90fb59..796271eeb0a37 100644 --- a/c10/test/core/impl/cow_test.cpp +++ b/c10/test/core/impl/cow_test.cpp @@ -9,6 +9,7 @@ #include #include +// NOLINTBEGIN(clang-analyzer-cplusplus*) namespace c10::impl { namespace { @@ -79,3 +80,4 @@ TEST_F(ContextTest, cow_deleter) { } // namespace } // namespace c10::impl +// NOLINTEND(clang-analyzer-cplusplus*) diff --git a/c10/test/util/Metaprogramming_test.cpp b/c10/test/util/Metaprogramming_test.cpp index 03650f8754b5e..4a3a4249f9bc0 100644 --- a/c10/test/util/Metaprogramming_test.cpp +++ b/c10/test/util/Metaprogramming_test.cpp @@ -94,14 +94,14 @@ struct CopyCounting { CopyCounting() : move_count(0), copy_count(0) {} CopyCounting(const CopyCounting& rhs) : move_count(rhs.move_count), copy_count(rhs.copy_count + 1) {} - CopyCounting(CopyCounting&& rhs) + CopyCounting(CopyCounting&& rhs) noexcept : move_count(rhs.move_count + 1), copy_count(rhs.copy_count) {} CopyCounting& operator=(const CopyCounting& rhs) { move_count = rhs.move_count; copy_count = rhs.copy_count + 1; return *this; } - CopyCounting& operator=(CopyCounting&& rhs) { + CopyCounting& operator=(CopyCounting&& rhs) noexcept { move_count = rhs.move_count + 1; copy_count = rhs.copy_count; return *this; @@ -175,7 +175,7 @@ namespace test_tuple_map { TEST(MetaprogrammingTest, TupleMap_simple) { auto result = tuple_map( std::tuple(3, 4, 5), - [](int32_t a) -> int16_t { return a + 1; }); + [](int32_t a) -> int16_t { return static_cast(a + 1); }); static_assert( std::is_same, decltype(result)>:: value, @@ -188,7 +188,7 @@ TEST(MetaprogrammingTest, TupleMap_simple) { TEST(MetaprogrammingTest, TupleMap_mapperTakesDifferentButConvertibleType) { auto result = tuple_map( std::tuple(3, 4, 5), - [](int64_t a) -> int16_t { return a + 1; }); + [](int64_t a) -> int16_t { return static_cast(a + 1); }); static_assert( std::is_same, decltype(result)>:: value, @@ -201,7 +201,7 @@ TEST(MetaprogrammingTest, TupleMap_mapperTakesDifferentButConvertibleType) { TEST(MetaprogrammingTest, TupleMap_mapperTakesConstRef) { auto result = tuple_map( std::tuple(3, 4, 5), - [](const int32_t& a) -> int16_t { return a + 1; }); + [](const int32_t& a) -> int16_t { return static_cast(a + 1); }); static_assert( std::is_same, decltype(result)>:: value, diff --git a/c10/test/util/TypeIndex_test.cpp b/c10/test/util/TypeIndex_test.cpp index 82b39f8df8c01..aa80acbe842c6 100644 --- a/c10/test/util/TypeIndex_test.cpp +++ b/c10/test/util/TypeIndex_test.cpp @@ -172,6 +172,7 @@ struct Functor final { }; #if C10_TYPENAME_SUPPORTS_CONSTEXPR static_assert( + // NOLINTNEXTLINE(misc-redundant-expression) get_fully_qualified_type_name&)>() == get_fully_qualified_type_name< typename c10::guts::infer_function_traits_t::func_type>(), diff --git a/c10/test/util/TypeTraits_test.cpp b/c10/test/util/TypeTraits_test.cpp index 7f0043c5be266..8130338609e08 100644 --- a/c10/test/util/TypeTraits_test.cpp +++ b/c10/test/util/TypeTraits_test.cpp @@ -156,12 +156,15 @@ void func() { static_assert(is_stateless_lambda::value, ""); int b = 4; + // NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores) auto stateful_lambda_1 = [&](int a) { return a + b; }; static_assert(!is_stateless_lambda::value, ""); + // NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores) auto stateful_lambda_2 = [=](int a) { return a + b; }; static_assert(!is_stateless_lambda::value, ""); + // NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores) auto stateful_lambda_3 = [b](int a) { return a + b; }; static_assert(!is_stateless_lambda::value, ""); diff --git a/c10/test/util/intrusive_ptr_test.cpp b/c10/test/util/intrusive_ptr_test.cpp index 434ffd7bd6615..14c12f422f2cd 100644 --- a/c10/test/util/intrusive_ptr_test.cpp +++ b/c10/test/util/intrusive_ptr_test.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -22,7 +21,7 @@ using c10::weak_intrusive_ptr; #ifdef __clang__ #pragma clang diagnostic ignored "-Wself-assign-overloaded" #endif - +// NOLINTBEGIN(clang-analyzer-cplusplus*) namespace { class SomeClass0Parameters : public intrusive_ptr_target {}; class SomeClass1Parameter : public intrusive_ptr_target { @@ -92,7 +91,7 @@ static_assert(NullType1::singleton() != NullType2::singleton()); } // namespace static_assert( - std::is_same::element_type>::value, + std::is_same_v::element_type>, "intrusive_ptr::element_type is wrong"); TEST(MakeIntrusiveTest, ClassWith0Parameters) { @@ -1716,7 +1715,7 @@ struct WeakReferenceToSelf : public intrusive_ptr_target { } // namespace static_assert( - std::is_same::element_type>::value, + std::is_same_v::element_type>, "weak_intrusive_ptr::element_type is wrong"); TEST( @@ -3544,3 +3543,4 @@ TEST( p->ptr = weak_intrusive_ptr( intrusive_ptr(p)); } +// NOLINTEND(clang-analyzer-cplusplus*) diff --git a/c10/test/util/ordered_preserving_dict_test.cpp b/c10/test/util/ordered_preserving_dict_test.cpp index 50c2bf2bdde42..29fde5c1ae394 100644 --- a/c10/test/util/ordered_preserving_dict_test.cpp +++ b/c10/test/util/ordered_preserving_dict_test.cpp @@ -444,6 +444,7 @@ TEST(OrderedPreservingDictTest, test_swap_empty) { swap(map, map2); TORCH_INTERNAL_ASSERT( + // NOLINTNEXTLINE(readability-container-size-empty) map == (ska_ordered:: order_preserving_flat_hash_map{})); diff --git a/c10/test/util/small_vector_test.cpp b/c10/test/util/small_vector_test.cpp index 3960b8916974b..e05d21ce88f13 100644 --- a/c10/test/util/small_vector_test.cpp +++ b/c10/test/util/small_vector_test.cpp @@ -874,6 +874,7 @@ TYPED_TEST(DualSmallVectorsTest, MoveAssignment) { } struct notassignable { + // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) int& x; notassignable(int& x) : x(x) {} }; @@ -1036,6 +1037,7 @@ TEST(SmallVectorTest, EmplaceBack) { } { SmallVector V; + // NOLINTNEXTLINE(bugprone-use-after-move) Emplaceable& back = V.emplace_back(std::move(A0), A1, std::move(A2), A3); EXPECT_TRUE(&back == &V.back()); EXPECT_TRUE(V.size() == 1);