diff --git a/c10/core/Allocator.h b/c10/core/Allocator.h index 3ea27fcb892..663471de5d0 100644 --- a/c10/core/Allocator.h +++ b/c10/core/Allocator.h @@ -226,7 +226,7 @@ struct AllocatorRegisterer { // per device struct C10_API MemoryReportingInfoBase : public c10::DebugInfoBase { MemoryReportingInfoBase(); - virtual ~MemoryReportingInfoBase() {} + ~MemoryReportingInfoBase() override = default; /** * alloc_size corresponds to the size of the ptr. diff --git a/c10/core/DispatchKeySet.h b/c10/core/DispatchKeySet.h index a2f7b31fa9c..acdd1740073 100644 --- a/c10/core/DispatchKeySet.h +++ b/c10/core/DispatchKeySet.h @@ -14,12 +14,12 @@ struct FunctionalityOffsetAndMask { FunctionalityOffsetAndMask(uint16_t offset, uint16_t mask) : offset(offset), mask(mask) {} // This needs to big enough to cover the size of the operator table. - uint16_t offset; + uint16_t offset{}; // See Note [No More Than 16 Backends] // This mask needs to be big enough to mask all of the backend bits. // We probably don't ever want to have more than 16 backend bits, so uint16_t // should be enough. - uint16_t mask; + uint16_t mask{}; }; static_assert( c10::num_runtime_entries < 65536, diff --git a/c10/core/InferenceMode.h b/c10/core/InferenceMode.h index 1f44c80fec4..fd93e5ba8c5 100644 --- a/c10/core/InferenceMode.h +++ b/c10/core/InferenceMode.h @@ -66,7 +66,7 @@ struct TORCH_API InferenceMode { DispatchKeySet excluded = enabled ? (prev_keyset.excluded_ | c10::autograd_dispatch_keyset) : (prev_keyset.excluded_ - c10::autograd_dispatch_keyset); - c10::impl::PODLocalDispatchKeySet cur_keyset; + c10::impl::PODLocalDispatchKeySet cur_keyset{}; cur_keyset.set_included(included); cur_keyset.set_excluded(excluded); c10::impl::_force_tls_local_dispatch_key_set(cur_keyset); diff --git a/c10/core/Scalar.h b/c10/core/Scalar.h index 0c124177e38..1ed97ed641b 100644 --- a/c10/core/Scalar.h +++ b/c10/core/Scalar.h @@ -292,7 +292,7 @@ class C10_API Scalar { Tag tag; union v_t { - double d; + double d{}; int64_t i; c10::complex z; c10::intrusive_ptr_target* p; diff --git a/c10/core/SymIntArrayRef.h b/c10/core/SymIntArrayRef.h index 46ffd2d0d13..e3622e5a8b3 100644 --- a/c10/core/SymIntArrayRef.h +++ b/c10/core/SymIntArrayRef.h @@ -19,7 +19,7 @@ inline at::IntArrayRef asIntArrayRefUnchecked(c10::SymIntArrayRef ar) { inline c10::optional asIntArrayRefSlowOpt( c10::SymIntArrayRef ar) { - for (c10::SymInt sci : ar) { + for (const c10::SymInt& sci : ar) { if (sci.is_symbolic()) { return c10::nullopt; } @@ -32,7 +32,7 @@ inline at::IntArrayRef asIntArrayRefSlow( c10::SymIntArrayRef ar, const char* file, int64_t line) { - for (c10::SymInt sci : ar) { + for (const c10::SymInt& sci : ar) { TORCH_CHECK( !sci.is_symbolic(), file, diff --git a/c10/core/TensorOptions.h b/c10/core/TensorOptions.h index 432fe4f1e4b..ee21ca727a9 100644 --- a/c10/core/TensorOptions.h +++ b/c10/core/TensorOptions.h @@ -582,7 +582,7 @@ inline TensorOptions layout(Layout layout) { /// Convenience function that returns a `TensorOptions` object with the `device` /// set to the given one. inline TensorOptions device(Device device) { - return TensorOptions().device(std::move(device)); + return TensorOptions().device(device); } /// Convenience function that returns a `TensorOptions` object with the diff --git a/c10/util/Array.h b/c10/util/Array.h index f33a36e8e84..87ae3786933 100644 --- a/c10/util/Array.h +++ b/c10/util/Array.h @@ -76,8 +76,8 @@ struct __array_traits<_Tp, 0> final { } }; -[[noreturn]] inline void __throw_out_of_range(std::string msg) { - throw std::out_of_range(std::move(msg)); +[[noreturn]] inline void __throw_out_of_range(const std::string& msg) { + throw std::out_of_range(msg); } } // namespace detail diff --git a/c10/util/BFloat16-inl.h b/c10/util/BFloat16-inl.h index 29fda9c3880..db823d3de16 100644 --- a/c10/util/BFloat16-inl.h +++ b/c10/util/BFloat16-inl.h @@ -11,14 +11,16 @@ C10_CLANG_DIAGNOSTIC_IGNORE("-Wimplicit-int-float-conversion") namespace c10 { /// Constructors -inline C10_HOST_DEVICE BFloat16::BFloat16(float value) { +inline C10_HOST_DEVICE BFloat16::BFloat16(float value) + : #if defined(CUDA_VERSION) && CUDA_VERSION >= 11000 && \ defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 800 - x = __bfloat16_as_ushort(__float2bfloat16(value)); + x(__bfloat16_as_ushort(__float2bfloat16(value))) #else - // RNE by default - x = detail::round_to_nearest_even(value); + // RNE by default + x(detail::round_to_nearest_even(value)) #endif +{ } /// Implicit conversions diff --git a/c10/util/Half-inl.h b/c10/util/Half-inl.h index 3ed8cf80d11..8e83027b315 100644 --- a/c10/util/Half-inl.h +++ b/c10/util/Half-inl.h @@ -27,14 +27,16 @@ namespace c10 { /// Constructors -inline C10_HOST_DEVICE Half::Half(float value) { +inline C10_HOST_DEVICE Half::Half(float value) + : #if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__) - x = __half_as_short(__float2half(value)); + x(__half_as_short(__float2half(value))) #elif defined(__SYCL_DEVICE_ONLY__) - x = sycl::bit_cast(sycl::half(value)); + x(sycl::bit_cast(sycl::half(value))) #else - x = detail::fp16_ieee_from_fp32_value(value); + x(detail::fp16_ieee_from_fp32_value(value)) #endif +{ } /// Implicit conversions diff --git a/c10/util/Optional.h b/c10/util/Optional.h index 1fad879b209..25a14c6afad 100644 --- a/c10/util/Optional.h +++ b/c10/util/Optional.h @@ -172,7 +172,7 @@ class bad_optional_access : public std::logic_error { template union storage_t { - unsigned char dummy_; + unsigned char dummy_{}; T value_; #if __cplusplus >= 202002L diff --git a/c10/util/SmallVector.h b/c10/util/SmallVector.h index e4672d666a9..7c5b24ed173 100644 --- a/c10/util/SmallVector.h +++ b/c10/util/SmallVector.h @@ -451,7 +451,7 @@ class SmallVectorTemplateBase : public SmallVectorTemplateCommon { void growAndAssign(size_t NumElts, const T& Elt) { // Grow manually in case Elt is an internal reference. - size_t NewCapacity; + size_t NewCapacity = 0; T* NewElts = mallocForGrow(NumElts, NewCapacity); std::uninitialized_fill_n(NewElts, NumElts, Elt); this->destroy_range(this->begin(), this->end()); @@ -462,7 +462,7 @@ class SmallVectorTemplateBase : public SmallVectorTemplateCommon { template T& growAndEmplaceBack(ArgTypes&&... Args) { // Grow manually in case one of Args is an internal reference. - size_t NewCapacity; + size_t NewCapacity = 0; T* NewElts = mallocForGrow(0, NewCapacity); ::new ((void*)(NewElts + this->size())) T(std::forward(Args)...); moveElementsForGrow(NewElts); @@ -493,7 +493,7 @@ class SmallVectorTemplateBase : public SmallVectorTemplateCommon { // Define this out-of-line to dissuade the C++ compiler from inlining it. template void SmallVectorTemplateBase::grow(size_t MinSize) { - size_t NewCapacity; + size_t NewCapacity = 0; T* NewElts = mallocForGrow(MinSize, NewCapacity); moveElementsForGrow(NewElts); takeAllocationForGrow(NewElts, NewCapacity); diff --git a/c10/util/string_view.h b/c10/util/string_view.h index 9ad4397d837..d476a71ec60 100644 --- a/c10/util/string_view.h +++ b/c10/util/string_view.h @@ -668,7 +668,7 @@ class basic_string_view final { }; const_pointer begin_; - size_type size_; + size_type size_{}; }; template