Skip to content

Commit

Permalink
[2/N] Enable clang-tidy to c10/test/*cpp (pytorch#110270)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyyever authored and pytorchmergebot committed Oct 1, 2023
1 parent ef5ff79 commit 55905c4
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ modernize-*,
performance-*,
readability-container-size-empty,
'
HeaderFilterRegex: '^(c10/(?!test)|torch/csrc/).*$'
HeaderFilterRegex: '^(c10/|torch/csrc/).*$'
AnalyzeTemporaryDtors: false
WarningsAsErrors: '*'
...
1 change: 0 additions & 1 deletion .lintrunner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ exclude_patterns = [
'**/*pb.h',
'**/*CUDA*',
'**/cuda/*pp',
'c10/test/**',
'third_party/**/*',
'torch/csrc/api/**',
'torch/csrc/autograd/functions/**',
Expand Down
2 changes: 2 additions & 0 deletions c10/test/core/impl/cow_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cstddef>
#include <memory>

// NOLINTBEGIN(clang-analyzer-cplusplus*)
namespace c10::impl {
namespace {

Expand Down Expand Up @@ -79,3 +80,4 @@ TEST_F(ContextTest, cow_deleter) {

} // namespace
} // namespace c10::impl
// NOLINTEND(clang-analyzer-cplusplus*)
10 changes: 5 additions & 5 deletions c10/test/util/Metaprogramming_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -175,7 +175,7 @@ namespace test_tuple_map {
TEST(MetaprogrammingTest, TupleMap_simple) {
auto result = tuple_map(
std::tuple<int32_t, int32_t, int32_t>(3, 4, 5),
[](int32_t a) -> int16_t { return a + 1; });
[](int32_t a) -> int16_t { return static_cast<int16_t>(a + 1); });
static_assert(
std::is_same<std::tuple<int16_t, int16_t, int16_t>, decltype(result)>::
value,
Expand All @@ -188,7 +188,7 @@ TEST(MetaprogrammingTest, TupleMap_simple) {
TEST(MetaprogrammingTest, TupleMap_mapperTakesDifferentButConvertibleType) {
auto result = tuple_map(
std::tuple<int32_t, int32_t, int32_t>(3, 4, 5),
[](int64_t a) -> int16_t { return a + 1; });
[](int64_t a) -> int16_t { return static_cast<int16_t>(a + 1); });
static_assert(
std::is_same<std::tuple<int16_t, int16_t, int16_t>, decltype(result)>::
value,
Expand All @@ -201,7 +201,7 @@ TEST(MetaprogrammingTest, TupleMap_mapperTakesDifferentButConvertibleType) {
TEST(MetaprogrammingTest, TupleMap_mapperTakesConstRef) {
auto result = tuple_map(
std::tuple<int32_t, int32_t, int32_t>(3, 4, 5),
[](const int32_t& a) -> int16_t { return a + 1; });
[](const int32_t& a) -> int16_t { return static_cast<int16_t>(a + 1); });
static_assert(
std::is_same<std::tuple<int16_t, int16_t, int16_t>, decltype(result)>::
value,
Expand Down
1 change: 1 addition & 0 deletions c10/test/util/TypeIndex_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ struct Functor final {
};
#if C10_TYPENAME_SUPPORTS_CONSTEXPR
static_assert(
// NOLINTNEXTLINE(misc-redundant-expression)
get_fully_qualified_type_name<std::string(int64_t, const Type<int>&)>() ==
get_fully_qualified_type_name<
typename c10::guts::infer_function_traits_t<Functor>::func_type>(),
Expand Down
3 changes: 3 additions & 0 deletions c10/test/util/TypeTraits_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,15 @@ void func() {
static_assert(is_stateless_lambda<decltype(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<decltype(stateful_lambda_1)>::value, "");

// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
auto stateful_lambda_2 = [=](int a) { return a + b; };
static_assert(!is_stateless_lambda<decltype(stateful_lambda_2)>::value, "");

// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
auto stateful_lambda_3 = [b](int a) { return a + b; };
static_assert(!is_stateless_lambda<decltype(stateful_lambda_3)>::value, "");

Expand Down
8 changes: 4 additions & 4 deletions c10/test/util/intrusive_ptr_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <gtest/gtest.h>
#include <map>
#include <memory>
#include <set>
#include <unordered_map>
#include <unordered_set>
Expand All @@ -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 {
Expand Down Expand Up @@ -92,7 +91,7 @@ static_assert(NullType1::singleton() != NullType2::singleton());
} // namespace

static_assert(
std::is_same<SomeClass, intrusive_ptr<SomeClass>::element_type>::value,
std::is_same_v<SomeClass, intrusive_ptr<SomeClass>::element_type>,
"intrusive_ptr<T>::element_type is wrong");

TEST(MakeIntrusiveTest, ClassWith0Parameters) {
Expand Down Expand Up @@ -1716,7 +1715,7 @@ struct WeakReferenceToSelf : public intrusive_ptr_target {
} // namespace

static_assert(
std::is_same<SomeClass, weak_intrusive_ptr<SomeClass>::element_type>::value,
std::is_same_v<SomeClass, weak_intrusive_ptr<SomeClass>::element_type>,
"weak_intrusive_ptr<T>::element_type is wrong");

TEST(
Expand Down Expand Up @@ -3544,3 +3543,4 @@ TEST(
p->ptr = weak_intrusive_ptr<intrusive_ptr_target>(
intrusive_ptr<intrusive_ptr_target>(p));
}
// NOLINTEND(clang-analyzer-cplusplus*)
1 change: 1 addition & 0 deletions c10/test/util/ordered_preserving_dict_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::int64_t, std::int64_t>{}));
Expand Down
2 changes: 2 additions & 0 deletions c10/test/util/small_vector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
};
Expand Down Expand Up @@ -1036,6 +1037,7 @@ TEST(SmallVectorTest, EmplaceBack) {
}
{
SmallVector<Emplaceable, 3> 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);
Expand Down

0 comments on commit 55905c4

Please sign in to comment.