CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
54 lines
1.8 KiB
ReStructuredText
54 lines
1.8 KiB
ReStructuredText
.. title:: clang-tidy - performance-no-automatic-move
|
|
|
|
performance-no-automatic-move
|
|
=============================
|
|
|
|
Finds local variables that cannot be automatically moved due to constness.
|
|
|
|
Under
|
|
`certain conditions <https://en.cppreference.com/w/cpp/language/return#automatic_move_from_local_variables_and_parameters>`_,
|
|
local values are automatically moved out when returning from a function. A
|
|
common mistake is to declare local ``lvalue`` variables ``const``, which
|
|
prevents the move.
|
|
|
|
Example `[1] <https://godbolt.org/z/x7SYYA>`_:
|
|
|
|
.. code-block:: c++
|
|
|
|
StatusOr<std::vector<int>> Cool() {
|
|
std::vector<int> obj = ...;
|
|
return obj; // calls StatusOr::StatusOr(std::vector<int>&&)
|
|
}
|
|
|
|
StatusOr<std::vector<int>> NotCool() {
|
|
const std::vector<int> obj = ...;
|
|
return obj; // calls `StatusOr::StatusOr(const std::vector<int>&)`
|
|
}
|
|
|
|
The former version (``Cool``) should be preferred over the latter (``NotCool``)
|
|
as it will avoid allocations and potentially large memory copies.
|
|
|
|
Semantics
|
|
---------
|
|
|
|
In the example above, ``StatusOr::StatusOr(T&&)`` have the same semantics as
|
|
long as the copy and move constructors for ``T`` have the same semantics. Note
|
|
that there is no guarantee that ``S::S(T&&)`` and ``S::S(const T&)`` have the
|
|
same semantics for any single ``S``, so we're not providing automated fixes for
|
|
this check, and judgement should be exerted when making the suggested changes.
|
|
|
|
-Wreturn-std-move
|
|
-----------------
|
|
|
|
Another case where the move cannot happen is the following:
|
|
|
|
.. code-block:: c++
|
|
|
|
StatusOr<std::vector<int>> Uncool() {
|
|
std::vector<int>&& obj = ...;
|
|
return obj; // calls `StatusOr::StatusOr(const std::vector<int>&)`
|
|
}
|
|
|
|
In that case the fix is more consensual: just `return std::move(obj)`.
|
|
This is handled by the `-Wreturn-std-move` warning.
|