Modify rule S5417: Add diff view
This commit is contained in:
parent
977028ea27
commit
c50c0e5e0e
@ -5,15 +5,15 @@
|
||||
* ``++std::move++`` takes an object and casts it as an ``++rvalue++`` reference, which indicates that resources can be "stolen" from this object.
|
||||
* ``++std::forward++`` has a single use-case: to cast a templated function parameter of type _forwarding reference_ (``++T&&++``) to the value category (``++lvalue++`` or ``++rvalue++``) the caller used to pass it. This allows ``++rvalue++`` arguments to be passed on as ``++rvalues++``, and ``++lvalues++`` to be passed on as ``++lvalues++``. This scheme is known as _perfect forwarding_. Note that the standard states that _"a forwarding reference is an rvalue reference to a cv-unqualified template parameter that does NOT represent a template parameter of a class template"_. Refer to the last noncompliant code example.
|
||||
|
||||
Since both rvalue references and forwarding references use the same notation (``++&&++``), an unwary developer might confuse them. If that happens, and a parameter is moved instead of forwarded, the original object can be emptied, probably crashing the software if the user tries to use the original object normally after the function call. An error in the other direction has less dire consequences, and might even work as intended if the right template argument is used, but the code would be clumsy and not clearly express the intent.
|
||||
Since both rvalue references and forwarding references use the same notation (``++&&++``), an unwary developer might confuse them. If that happens, and a parameter is moved instead of forwarded, the original object can be emptied, probably crashing the software if the user tries to use the original object normally after the function call. An error in the other direction has less dire consequences and might even work as intended if the right template argument is used, but the code would be clumsy and not clearly express the intent.
|
||||
|
||||
|
||||
This rule raises an issue when ``++std::forward++`` is used with a parameter not passed as a forwarding reference, or when ``++std::move++`` is used on a parameter passed as a forwarding reference.
|
||||
This rule raises an issue when ``++std::forward++`` is used with a parameter not passed as a forwarding reference or when ``++std::move++`` is used on a parameter passed as a forwarding reference.
|
||||
|
||||
|
||||
=== Noncompliant code example
|
||||
|
||||
[source,cpp]
|
||||
[source,cpp,diff-id=1,diff-type=noncompliant]
|
||||
----
|
||||
#include <utility>
|
||||
|
||||
@ -49,7 +49,7 @@ struct C {
|
||||
|
||||
=== Compliant solution
|
||||
|
||||
[source,cpp]
|
||||
[source,cpp,diff-id=1,diff-type=compliant]
|
||||
----
|
||||
#include <utility>
|
||||
|
||||
@ -73,11 +73,11 @@ void (std::vector<T>&& t){
|
||||
std::move(t);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename T>
|
||||
struct C {
|
||||
C(T&& t) {
|
||||
C(T&& t) {
|
||||
g(std::move(t));
|
||||
}
|
||||
}
|
||||
};
|
||||
----
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user