diff --git a/.clang-tidy b/.clang-tidy index 8e3169ab93b..72e0de1a1fc 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -23,7 +23,6 @@ Checks: - 'performance-*' - '-performance-noexcept-swap' - '-performance-enum-size' - - '-performance-unnecessary-copy-initialization' - '-performance-unnecessary-value-param' # END REMOVE ME # HICPP is 99% aliased to other checks (mostly modernize-* and bugprone-*). We don't diff --git a/cub/cub/thread/thread_operators.cuh b/cub/cub/thread/thread_operators.cuh index 6b214e106be..1633ba51755 100644 --- a/cub/cub/thread/thread_operators.cuh +++ b/cub/cub/thread/thread_operators.cuh @@ -257,10 +257,7 @@ public: template _CCCL_HOST_DEVICE _CCCL_FORCEINLINE T operator()(const T& a, const T& b) { - T _a(a); - T _b(b); - - return scan_op(_b, _a); + return scan_op(b, a); } }; diff --git a/libcudacxx/test/libcudacxx/cuda/containers/buffer/constructor.cu b/libcudacxx/test/libcudacxx/cuda/containers/buffer/constructor.cu index 661f176ce45..66b227ad01f 100644 --- a/libcudacxx/test/libcudacxx/cuda/containers/buffer/constructor.cu +++ b/libcudacxx/test/libcudacxx/cuda/containers/buffer/constructor.cu @@ -209,14 +209,14 @@ C2H_CCCLRT_TEST("cuda::buffer constructors", "[container][buffer]", test_types) static_assert(!cuda::std::is_nothrow_copy_constructible::value, ""); { // can be copy constructed from empty input const Buffer input{stream, resource, 0, cuda::no_init}; - Buffer buf(input); + Buffer buf(input); // NOLINT(performance-unnecessary-copy-initialization) CCCLRT_CHECK(buf.empty()); CCCLRT_CHECK(buf.alignment() == input.alignment()); } { // can be copy constructed from non-empty input const Buffer input{stream, resource, {T(1), T(42), T(1337), T(0), T(12), T(-1)}}; - Buffer buf(input); + Buffer buf(input); // NOLINT(performance-unnecessary-copy-initialization) CCCLRT_CHECK(buf.alignment() == input.alignment()); CCCLRT_CHECK(is_pointer_aligned(buf.data(), buf.alignment())); CCCLRT_CHECK(check_offseted_pointer(buf.data())); @@ -228,7 +228,7 @@ C2H_CCCLRT_TEST("cuda::buffer constructors", "[container][buffer]", test_types) const ::cuda::std::size_t alignment = ::cuda::mr::default_cuda_malloc_alignment / 2; const auto env = ::cuda::std::execution::prop{::cuda::allocation_alignment, alignment}; const Buffer input{stream, resource, 5, cuda::no_init, env}; - Buffer buf(input); + Buffer buf(input); // NOLINT(performance-unnecessary-copy-initialization) CCCLRT_CHECK(buf.alignment() == alignment); CCCLRT_CHECK(input.alignment() == alignment); CCCLRT_CHECK(cuda::allocation_alignment(buf) == alignment); diff --git a/thrust/testing/pair.cu b/thrust/testing/pair.cu index 86e1448da5f..9bde93fba99 100644 --- a/thrust/testing/pair.cu +++ b/thrust/testing/pair.cu @@ -33,7 +33,7 @@ struct TestPairManipulation ASSERT_EQUAL(p1.second, sp.second); // test initialization - P p3 = p2; + P p3 = p2; // NOLINT(performance-unnecessary-copy-initialization) ASSERT_EQUAL(p2.first, p3.first); ASSERT_EQUAL(p2.second, p3.second); diff --git a/thrust/testing/permutation_iterator.cu b/thrust/testing/permutation_iterator.cu index 0a3932d524a..61361208712 100644 --- a/thrust/testing/permutation_iterator.cu +++ b/thrust/testing/permutation_iterator.cu @@ -243,7 +243,7 @@ void TestPermutationIteratorHostDeviceScatter() // scatter device->host thrust::copy(d_source.begin(), d_source.end(), p_h_output); - HostVector href(dref); + HostVector href = dref; ASSERT_EQUAL(h_output, href); } DECLARE_UNITTEST(TestPermutationIteratorHostDeviceScatter); diff --git a/thrust/testing/uninitialized_fill.cu b/thrust/testing/uninitialized_fill.cu index 19008fefaba..40bb307658d 100644 --- a/thrust/testing/uninitialized_fill.cu +++ b/thrust/testing/uninitialized_fill.cu @@ -148,7 +148,7 @@ struct TestUninitializedFillNonPOD ASSERT_EQUAL(false, exemplar.copy_constructed_on_device); ASSERT_EQUAL(false, exemplar.copy_constructed_on_host); - T host_copy_of_exemplar(exemplar); + T host_copy_of_exemplar(exemplar); // NOLINT(performance-unnecessary-copy-initialization) ASSERT_EQUAL(false, exemplar.copy_constructed_on_device); ASSERT_EQUAL(true, exemplar.copy_constructed_on_host); @@ -216,7 +216,7 @@ struct TestUninitializedFillNNonPOD ASSERT_EQUAL(false, exemplar.copy_constructed_on_device); ASSERT_EQUAL(false, exemplar.copy_constructed_on_host); - T host_copy_of_exemplar(exemplar); + T host_copy_of_exemplar(exemplar); // NOLINT(performance-unnecessary-copy-initialization) ASSERT_EQUAL(false, exemplar.copy_constructed_on_device); ASSERT_EQUAL(true, exemplar.copy_constructed_on_host); diff --git a/thrust/testing/unittest/testframework.h b/thrust/testing/unittest/testframework.h index 891904400ac..5a7e3076a83 100644 --- a/thrust/testing/unittest/testframework.h +++ b/thrust/testing/unittest/testframework.h @@ -474,71 +474,71 @@ class UnitTestDriver TEST##UnitTest TEST##Instance // Macro to create instances of a test for several array sizes. -#define DECLARE_SIZED_UNITTEST(TEST) \ - class TEST##UnitTest : public UnitTest \ - { \ - public: \ - TEST##UnitTest() \ - : UnitTest(#TEST) \ - {} \ - void run() \ - { \ - std::vector sizes = get_test_sizes(); \ - for (size_t i = 0; i != sizes.size(); ++i) \ - { \ - TEST(sizes[i]); \ - } \ - } \ - }; \ +#define DECLARE_SIZED_UNITTEST(TEST) \ + class TEST##UnitTest : public UnitTest \ + { \ + public: \ + TEST##UnitTest() \ + : UnitTest(#TEST) \ + {} \ + void run() \ + { \ + const std::vector& sizes = get_test_sizes(); \ + for (size_t i = 0; i != sizes.size(); ++i) \ + { \ + TEST(sizes[i]); \ + } \ + } \ + }; \ TEST##UnitTest TEST##Instance // Macro to create instances of a test for several data types and array sizes -#define DECLARE_VARIABLE_UNITTEST(TEST) \ - class TEST##UnitTest : public UnitTest \ - { \ - public: \ - TEST##UnitTest() \ - : UnitTest(#TEST) \ - {} \ - void run() \ - { \ - std::vector sizes = get_test_sizes(); \ - for (size_t i = 0; i != sizes.size(); ++i) \ - { \ - TEST(sizes[i]); \ - TEST(sizes[i]); \ - TEST(sizes[i]); \ - TEST(sizes[i]); \ - TEST(sizes[i]); \ - TEST(sizes[i]); \ - TEST(sizes[i]); \ - TEST(sizes[i]); \ - } \ - } \ - }; \ +#define DECLARE_VARIABLE_UNITTEST(TEST) \ + class TEST##UnitTest : public UnitTest \ + { \ + public: \ + TEST##UnitTest() \ + : UnitTest(#TEST) \ + {} \ + void run() \ + { \ + const std::vector& sizes = get_test_sizes(); \ + for (size_t i = 0; i != sizes.size(); ++i) \ + { \ + TEST(sizes[i]); \ + TEST(sizes[i]); \ + TEST(sizes[i]); \ + TEST(sizes[i]); \ + TEST(sizes[i]); \ + TEST(sizes[i]); \ + TEST(sizes[i]); \ + TEST(sizes[i]); \ + } \ + } \ + }; \ TEST##UnitTest TEST##Instance -#define DECLARE_INTEGRAL_VARIABLE_UNITTEST(TEST) \ - class TEST##UnitTest : public UnitTest \ - { \ - public: \ - TEST##UnitTest() \ - : UnitTest(#TEST) \ - {} \ - void run() \ - { \ - std::vector sizes = get_test_sizes(); \ - for (size_t i = 0; i != sizes.size(); ++i) \ - { \ - TEST(sizes[i]); \ - TEST(sizes[i]); \ - TEST(sizes[i]); \ - TEST(sizes[i]); \ - TEST(sizes[i]); \ - TEST(sizes[i]); \ - } \ - } \ - }; \ +#define DECLARE_INTEGRAL_VARIABLE_UNITTEST(TEST) \ + class TEST##UnitTest : public UnitTest \ + { \ + public: \ + TEST##UnitTest() \ + : UnitTest(#TEST) \ + {} \ + void run() \ + { \ + const std::vector& sizes = get_test_sizes(); \ + for (size_t i = 0; i != sizes.size(); ++i) \ + { \ + TEST(sizes[i]); \ + TEST(sizes[i]); \ + TEST(sizes[i]); \ + TEST(sizes[i]); \ + TEST(sizes[i]); \ + TEST(sizes[i]); \ + } \ + } \ + }; \ TEST##UnitTest TEST##Instance #define DECLARE_GENERIC_UNITTEST_WITH_TYPES_AND_NAME(TEST, TYPES, NAME) \ @@ -590,7 +590,7 @@ class VariableUnitTest : public UnitTest void run() { - std::vector sizes = get_test_sizes(); + const std::vector& sizes = get_test_sizes(); for (size_t i = 0; i != sizes.size(); ++i) { // get the first type in the list diff --git a/thrust/thrust/detail/memory_algorithms.h b/thrust/thrust/detail/memory_algorithms.h index b7bdfb9ad69..b21fac4a3c5 100644 --- a/thrust/thrust/detail/memory_algorithms.h +++ b/thrust/thrust/detail/memory_algorithms.h @@ -65,7 +65,8 @@ _CCCL_HOST_DEVICE ForwardIt destroy(Allocator const& alloc, ForwardIt first, For using traits = typename ::cuda::std::allocator_traits<::cuda::std::remove_cvref_t>::template rebind_traits; - typename traits::allocator_type alloc_T(alloc); + // allocator_type might not be same as Allocator + const typename traits::allocator_type alloc_T(alloc); // NOLINT(performance-unnecessary-copy-initialization) for (; first != last; ++first) { @@ -93,7 +94,8 @@ _CCCL_HOST_DEVICE ForwardIt destroy_n(Allocator const& alloc, ForwardIt first, S using traits = typename ::cuda::std::allocator_traits<::cuda::std::remove_cvref_t>::template rebind_traits; - typename traits::allocator_type alloc_T(alloc); + // allocator_type might not be same as Allocator + const typename traits::allocator_type alloc_T(alloc); // NOLINT(performance-unnecessary-copy-initialization) for (; n > 0; (void) ++first, --n) { diff --git a/thrust/thrust/system/detail/sequential/adjacent_difference.h b/thrust/thrust/system/detail/sequential/adjacent_difference.h index c090d25ca32..1bd45fb9ca4 100644 --- a/thrust/thrust/system/detail/sequential/adjacent_difference.h +++ b/thrust/thrust/system/detail/sequential/adjacent_difference.h @@ -44,7 +44,7 @@ _CCCL_HOST_DEVICE OutputIterator adjacent_difference( while (++first != last) { - InputType next = *first; + InputType next = *first; // NOLINT(performance-unnecessary-copy-initialization) *(++result) = binary_op(next, curr); curr = next; } diff --git a/thrust/thrust/system/detail/sequential/insertion_sort.h b/thrust/thrust/system/detail/sequential/insertion_sort.h index ee119d7226d..0400d114854 100644 --- a/thrust/thrust/system/detail/sequential/insertion_sort.h +++ b/thrust/thrust/system/detail/sequential/insertion_sort.h @@ -85,7 +85,7 @@ _CCCL_HOST_DEVICE void insertion_sort_by_key( for (; i1 != last1; ++i1, ++i2) { value_type1 tmp1 = *i1; - value_type2 tmp2 = *i2; + value_type2 tmp2 = *i2; // NOLINT(performance-unnecessary-copy-initialization) if (wrapped_comp(tmp1, *first1)) { diff --git a/thrust/thrust/system/detail/sequential/scan_by_key.h b/thrust/thrust/system/detail/sequential/scan_by_key.h index 9ec699e14a3..147e08750f3 100644 --- a/thrust/thrust/system/detail/sequential/scan_by_key.h +++ b/thrust/thrust/system/detail/sequential/scan_by_key.h @@ -54,7 +54,7 @@ _CCCL_HOST_DEVICE OutputIterator inclusive_scan_by_key( for (++first1, ++first2, ++result; first1 != last1; ++first1, (void) ++first2, (void) ++result) { - KeyType key = *first1; + KeyType key = *first1; // NOLINT(performance-unnecessary-copy-initialization) if (binary_pred(prev_key, key)) { @@ -107,7 +107,7 @@ _CCCL_HOST_DEVICE OutputIterator exclusive_scan_by_key( for (++first1, ++first2, ++result; first1 != last1; ++first1, (void) ++first2, (void) ++result) { - KeyType key = *first1; + KeyType key = *first1; // NOLINT(performance-unnecessary-copy-initialization) // use temp to permit in-place scans temp_value = *first2;