When I was using visual studio 2022, I noticed that its std::move
function defines the [[msvc::intrinsic]]
attribute as a macro. /std:c++latest
produces some non-standard behavior
That is, the lifetime of the temporary object is extended, but in principle, the move function call has a return, can not be extended.
I tried the toggle option standard, but it was the same.
Here's a demo I wrote, replacing std::move
with my own mmove, adding [[msvc::intrinsic]]
attributes, and a normal control group.
I want to know what this property does and why msvc is designed this way.
#include<iostream>
struct A{
~A() { puts(__FUNCTION__); }
};
template <class Ty>//Added an attribute, behavior equivalent to std::move in /std:c++latest, non-standard, extended lifetime
[[msvc::intrinsic]] constexpr std::remove_reference_t<Ty>&& mmove(Ty&& Arg) noexcept {
return static_cast<std::remove_reference_t<Ty>&&>(Arg);
}
template <class Ty>
constexpr std::remove_reference_t<Ty>&& nmove(Ty&& Arg) noexcept {
return static_cast<std::remove_reference_t<Ty>&&>(Arg);
}
int main()
{
{
A&& rvalue = mmove(A{});
puts(__FUNCTION__);
}
puts("------");
{
A&& rvalue = nmove(A{});
puts(__FUNCTION__);
}
}
I look forward to getting a detailed explanation of the '[[msvc::intrinsic]]' properties.