diff --git a/.clang-tidy b/.clang-tidy index 2e827043334859..576a36fc9bf92e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -30,8 +30,13 @@ cppcoreguidelines-*, -facebook-hte-RelativeInclude, hicpp-exception-baseclass, hicpp-avoid-goto, -misc-unused-alias-decls, -misc-unused-using-decls, +misc-*, +-misc-const-correctness, +-misc-use-anonymous-namespace, +-misc-unused-parameters, +-misc-no-recursion, +-misc-non-private-member-variables-in-classes, +-misc-confusable-identifiers, modernize-*, -modernize-concat-nested-namespaces, -modernize-macro-to-enum, diff --git a/c10/util/Logging.cpp b/c10/util/Logging.cpp index ff8e1d6ccc981f..8dcf13ab9baa7c 100644 --- a/c10/util/Logging.cpp +++ b/c10/util/Logging.cpp @@ -44,7 +44,7 @@ void ThrowEnforceNotMet( if (FLAGS_caffe2_use_fatal_for_enforce) { LOG(FATAL) << e.msg(); } - throw e; + throw std::move(e); } void ThrowEnforceNotMet( diff --git a/c10/util/numa.cpp b/c10/util/numa.cpp index 7d87a9a2e6d87d..be138a0250d5f7 100644 --- a/c10/util/numa.cpp +++ b/c10/util/numa.cpp @@ -79,8 +79,7 @@ void NUMAMove(void* ptr, size_t size, int numa_node_id) { uintptr_t page_start_ptr = ((reinterpret_cast(ptr)) & ~(getpagesize() - 1)); - // NOLINTNEXTLINE(cppcoreguidelines-narrowing-conversions) - // NOLINTNEXTLINE(bugprone-narrowing-conversions) + // NOLINTNEXTLINE(*-conversions) ptrdiff_t offset = reinterpret_cast(ptr) - page_start_ptr; // Avoid extra dynamic allocation and NUMA api calls AT_ASSERT( diff --git a/torch/csrc/Generator.cpp b/torch/csrc/Generator.cpp index 065564c577c68e..cd409d4e760bf6 100644 --- a/torch/csrc/Generator.cpp +++ b/torch/csrc/Generator.cpp @@ -247,6 +247,7 @@ PyTypeObject THPGeneratorType = { nullptr, /* tp_getattro */ nullptr, /* tp_setattro */ nullptr, /* tp_as_buffer */ + // NOLINTNEXTLINE(misc-redundant-expression) Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ nullptr, /* tp_doc */ nullptr, /* tp_traverse */ diff --git a/torch/csrc/Storage.cpp b/torch/csrc/Storage.cpp index e6de19735148c8..fb07d5fff81ebb 100644 --- a/torch/csrc/Storage.cpp +++ b/torch/csrc/Storage.cpp @@ -627,6 +627,7 @@ PyTypeObject THPStorageMetaType = { nullptr, /* tp_getattro */ nullptr, /* tp_setattro */ nullptr, /* tp_as_buffer */ + // NOLINTNEXTLINE(misc-redundant-expression) Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ nullptr, /* tp_doc */ nullptr, /* tp_traverse */ @@ -670,6 +671,7 @@ PyTypeObject THPStorageType = { nullptr, /* tp_getattro */ nullptr, /* tp_setattro */ nullptr, /* tp_as_buffer */ + // NOLINTNEXTLINE(misc-redundant-expression) Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ nullptr, /* tp_doc */ nullptr, /* tp_traverse */ diff --git a/torch/csrc/Stream.cpp b/torch/csrc/Stream.cpp index e7d1405d38cb7a..bd8abb0ecde2d8 100644 --- a/torch/csrc/Stream.cpp +++ b/torch/csrc/Stream.cpp @@ -130,6 +130,7 @@ PyTypeObject THPStreamType = { nullptr, /* tp_getattro */ nullptr, /* tp_setattro */ nullptr, /* tp_as_buffer */ + // NOLINTNEXTLINE(misc-redundant-expression) Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ nullptr, /* tp_doc */ nullptr, /* tp_traverse */ diff --git a/torch/csrc/autograd/python_cpp_function.cpp b/torch/csrc/autograd/python_cpp_function.cpp index ad9ccbcf0bdac7..1f957b17230167 100644 --- a/torch/csrc/autograd/python_cpp_function.cpp +++ b/torch/csrc/autograd/python_cpp_function.cpp @@ -216,6 +216,7 @@ PyTypeObject* _initFunctionPyTypeObject( const char* name, PyGetSetDef* function_properties, PyMethodDef* function_methods) { + // NOLINTNEXTLINE(misc-redundant-expression) type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC; type.tp_name = name; type.tp_basicsize = sizeof(THPCppFunction); diff --git a/torch/csrc/autograd/python_engine.cpp b/torch/csrc/autograd/python_engine.cpp index 8b48c965f730bf..08106c008980b9 100644 --- a/torch/csrc/autograd/python_engine.cpp +++ b/torch/csrc/autograd/python_engine.cpp @@ -422,6 +422,7 @@ PyTypeObject THPEngineType = { nullptr, /* tp_getattro */ nullptr, /* tp_setattro */ nullptr, /* tp_as_buffer */ + // NOLINTNEXTLINE(misc-redundant-expression) Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ nullptr, /* tp_doc */ nullptr, /* tp_traverse */ diff --git a/torch/csrc/autograd/python_function.cpp b/torch/csrc/autograd/python_function.cpp index 4127b83cb55058..c40fb7f53ef58f 100644 --- a/torch/csrc/autograd/python_function.cpp +++ b/torch/csrc/autograd/python_function.cpp @@ -68,7 +68,7 @@ namespace { void throw_python_error() { python_error err; err.persist(); - throw err; + throw std::move(err); } } // namespace @@ -1557,6 +1557,7 @@ PyTypeObject THPFunctionType = { nullptr, /* tp_getattro */ nullptr, /* tp_setattro */ nullptr, /* tp_as_buffer */ + // NOLINTNEXTLINE(misc-redundant-expression) Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ nullptr, /* tp_doc */ diff --git a/torch/csrc/autograd/python_legacy_variable.cpp b/torch/csrc/autograd/python_legacy_variable.cpp index 4ac502ae1ab22e..3f81e87c630c39 100644 --- a/torch/csrc/autograd/python_legacy_variable.cpp +++ b/torch/csrc/autograd/python_legacy_variable.cpp @@ -131,6 +131,7 @@ PyTypeObject THPLegacyVariableType = { nullptr, /* tp_getattro */ nullptr, /* tp_setattro */ nullptr, /* tp_as_buffer */ + // NOLINTNEXTLINE(misc-redundant-expression) Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ nullptr, /* tp_doc */ nullptr, /* tp_traverse */ diff --git a/torch/csrc/autograd/python_variable.cpp b/torch/csrc/autograd/python_variable.cpp index 292e9ce76edbca..a0ddcf10bc81d2 100644 --- a/torch/csrc/autograd/python_variable.cpp +++ b/torch/csrc/autograd/python_variable.cpp @@ -1666,6 +1666,7 @@ PyTypeObject THPVariableMetaType = { nullptr, /* tp_getattro */ nullptr, /* tp_setattro */ nullptr, /* tp_as_buffer */ + // NOLINTNEXTLINE(misc-redundant-expression) Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ nullptr, /* tp_doc */ nullptr, /* tp_traverse */ @@ -1711,6 +1712,7 @@ PyTypeObject THPVariableType = { nullptr, /* tp_getattro */ nullptr, /* tp_setattro */ nullptr, /* tp_as_buffer */ + // NOLINTNEXTLINE(misc-redundant-expression) Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ nullptr, /* tp_doc */ diff --git a/torch/csrc/tensor/python_tensor.cpp b/torch/csrc/tensor/python_tensor.cpp index 489b141e5f9750..0e57842da125a6 100644 --- a/torch/csrc/tensor/python_tensor.cpp +++ b/torch/csrc/tensor/python_tensor.cpp @@ -182,6 +182,7 @@ static PyTypeObject metaclass = { }; static void py_initialize_metaclass(PyTypeObject& metaclass) { + // NOLINTNEXTLINE(misc-redundant-expression) metaclass.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; metaclass.tp_methods = metaclass_methods; metaclass.tp_getset = metaclass_properties; diff --git a/torch/csrc/utils/python_arg_parser.cpp b/torch/csrc/utils/python_arg_parser.cpp index 0ed3acde0d110c..e48899e91d4aba 100644 --- a/torch/csrc/utils/python_arg_parser.cpp +++ b/torch/csrc/utils/python_arg_parser.cpp @@ -791,7 +791,7 @@ static bool is_int_list( // Make sure none of the later arguments are SymInt // NB: do NOT check that the later arguments are ints, as this is // BC-breaking for FX - for (int i = 1; i < len; i++) { + for (Py_ssize_t i = 1; i < len; i++) { if (torch::is_symint( py::reinterpret_steal(PySequence_GetItem(obj, i)))) { if (failed_idx != nullptr) {