90 lines · plain
1.. title:: clang-tidy - cppcoreguidelines-rvalue-reference-param-not-moved2 3cppcoreguidelines-rvalue-reference-param-not-moved4==================================================5 6Warns when an rvalue reference function parameter is never moved within7the function body.8 9Rvalue reference parameters indicate a parameter that should be moved with10``std::move`` from within the function body. Any such parameter that is11never moved is confusing and potentially indicative of a buggy program.12 13Example:14 15.. code-block:: c++16 17 void logic(std::string&& Input) {18 std::string Copy(Input); // Oops - forgot to std::move19 }20 21Note that parameters that are unused and marked as such will not be diagnosed.22 23Example:24 25.. code-block:: c++26 27 void conditional_use([[maybe_unused]] std::string&& Input) {28 // No diagnostic here since Input is unused and marked as such29 }30 31Options32-------33 34.. option:: AllowPartialMove35 36 If set to `true`, the check accepts ``std::move`` calls containing any37 subexpression containing the parameter. CppCoreGuideline F.18 officially38 mandates that the parameter itself must be moved. Default is `false`.39 40 .. code-block:: c++41 42 // 'p' is flagged by this check if and only if AllowPartialMove is false43 void move_members_of(pair<Obj, Obj>&& p) {44 pair<Obj, Obj> other;45 other.first = std::move(p.first);46 other.second = std::move(p.second);47 }48 49 // 'p' is never flagged by this check50 void move_whole_pair(pair<Obj, Obj>&& p) {51 pair<Obj, Obj> other = std::move(p);52 }53 54.. option:: IgnoreUnnamedParams55 56 If set to `true`, the check ignores unnamed rvalue reference parameters.57 Default is `false`.58 59.. option:: IgnoreNonDeducedTemplateTypes60 61 If set to `true`, the check ignores non-deduced template type rvalue62 reference parameters. Default is `false`.63 64 .. code-block:: c++65 66 template <class T>67 struct SomeClass {68 // Below, 'T' is not deduced and 'T&&' is an rvalue reference type.69 // This will be flagged if and only if IgnoreNonDeducedTemplateTypes is70 // false. One suggested fix would be to specialize the class for 'T' and71 // 'T&' separately (e.g., see std::future), or allow only one of 'T' or72 // 'T&' instantiations of SomeClass (e.g., see std::optional).73 SomeClass(T&& t) { }74 };75 76 // Never flagged, since 'T' is a forwarding reference in a deduced context77 template <class T>78 void forwarding_ref(T&& t) {79 T other = std::forward<T>(t);80 }81 82.. option:: MoveFunction83 84 Specify the function used for moving. Default is `::std::move`.85 86This check implements `F.1887<http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f18-for-will-move-from-parameters-pass-by-x-and-stdmove-the-parameter>`_88from the C++ Core Guidelines.89 90