mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
[2/N] Enable clang-tidy to c10/test/*cpp (#110270)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/110270 Approved by: https://github.com/Skylion007, https://github.com/kit1980
This commit is contained in:
@ -49,7 +49,7 @@ modernize-*,
|
||||
performance-*,
|
||||
readability-container-size-empty,
|
||||
'
|
||||
HeaderFilterRegex: '^(c10/(?!test)|torch/csrc/).*$'
|
||||
HeaderFilterRegex: '^(c10/|torch/csrc/).*$'
|
||||
AnalyzeTemporaryDtors: false
|
||||
WarningsAsErrors: '*'
|
||||
...
|
||||
|
@ -262,7 +262,6 @@ exclude_patterns = [
|
||||
'**/*pb.h',
|
||||
'**/*CUDA*',
|
||||
'**/cuda/*pp',
|
||||
'c10/test/**',
|
||||
'third_party/**/*',
|
||||
'torch/csrc/api/**',
|
||||
'torch/csrc/autograd/functions/**',
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
|
||||
// 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*)
|
||||
|
@ -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<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,
|
||||
@ -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,
|
||||
@ -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,
|
||||
|
@ -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>(),
|
||||
|
@ -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, "");
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
@ -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<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) {
|
||||
@ -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(
|
||||
@ -3544,3 +3543,4 @@ TEST(
|
||||
p->ptr = weak_intrusive_ptr<intrusive_ptr_target>(
|
||||
intrusive_ptr<intrusive_ptr_target>(p));
|
||||
}
|
||||
// NOLINTEND(clang-analyzer-cplusplus*)
|
||||
|
@ -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>{}));
|
||||
|
@ -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<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);
|
||||
|
Reference in New Issue
Block a user