Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48eb4a4

Browse files
add support for [[msvc::intrinsic]] (microsoft#3182)
Co-authored-by: Casey Carter <[email protected]>
1 parent 99e4c99 commit 48eb4a4

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

stl/inc/type_traits

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,26 +1423,25 @@ template <class _Type, template <class...> class _Template>
14231423
struct _Is_specialization : bool_constant<_Is_specialization_v<_Type, _Template>> {};
14241424

14251425
_EXPORT_STD template <class _Ty>
1426-
_NODISCARD constexpr _Ty&& forward(
1427-
remove_reference_t<_Ty>& _Arg) noexcept { // forward an lvalue as either an lvalue or an rvalue
1426+
_NODISCARD _MSVC_INTRINSIC constexpr _Ty&& forward(remove_reference_t<_Ty>& _Arg) noexcept {
14281427
return static_cast<_Ty&&>(_Arg);
14291428
}
14301429

14311430
_EXPORT_STD template <class _Ty>
1432-
_NODISCARD constexpr _Ty&& forward(remove_reference_t<_Ty>&& _Arg) noexcept { // forward an rvalue as an rvalue
1431+
_NODISCARD _MSVC_INTRINSIC constexpr _Ty&& forward(remove_reference_t<_Ty>&& _Arg) noexcept {
14331432
static_assert(!is_lvalue_reference_v<_Ty>, "bad forward call");
14341433
return static_cast<_Ty&&>(_Arg);
14351434
}
14361435

14371436
_EXPORT_STD template <class _Ty>
1438-
_NODISCARD constexpr remove_reference_t<_Ty>&& move(_Ty&& _Arg) noexcept { // forward _Arg as movable
1437+
_NODISCARD _MSVC_INTRINSIC constexpr remove_reference_t<_Ty>&& move(_Ty&& _Arg) noexcept {
14391438
return static_cast<remove_reference_t<_Ty>&&>(_Arg);
14401439
}
14411440

14421441
_EXPORT_STD template <class _Ty>
1443-
_NODISCARD constexpr conditional_t<!is_nothrow_move_constructible_v<_Ty> && is_copy_constructible_v<_Ty>, const _Ty&,
1444-
_Ty&&>
1445-
move_if_noexcept(_Ty& _Arg) noexcept { // forward _Arg as movable, sometimes
1442+
_NODISCARD _MSVC_INTRINSIC constexpr //
1443+
conditional_t<!is_nothrow_move_constructible_v<_Ty> && is_copy_constructible_v<_Ty>, const _Ty&, _Ty&&>
1444+
move_if_noexcept(_Ty& _Arg) noexcept {
14461445
return _STD move(_Arg);
14471446
}
14481447

stl/inc/utility

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ _EXPORT_STD [[noreturn]] __forceinline void unreachable() noexcept /* strengthen
820820
}
821821

822822
_EXPORT_STD template <class _Ty, class _Uty>
823-
_NODISCARD constexpr auto&& forward_like(_Uty&& _Ux) noexcept {
823+
_NODISCARD _MSVC_INTRINSIC constexpr auto&& forward_like(_Uty&& _Ux) noexcept {
824824
static_assert(_Can_reference<_Ty>, "std::forward_like's first template argument must be a referenceable type.");
825825

826826
using _UnrefT = remove_reference_t<_Ty>;

stl/inc/yvals_core.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,11 @@
622622
#pragma push_macro("msvc")
623623
#pragma push_macro("known_semantics")
624624
#pragma push_macro("noop_dtor")
625+
#pragma push_macro("intrinsic")
625626
#undef msvc
626627
#undef known_semantics
627628
#undef noop_dtor
629+
#undef intrinsic
628630

629631
#ifndef __has_cpp_attribute
630632
#define _HAS_MSVC_ATTRIBUTE(x) 0
@@ -650,7 +652,16 @@
650652
#define _MSVC_NOOP_DTOR
651653
#endif
652654

655+
// Should we use [[msvc::intrinsic]] allowing the compiler to implement the
656+
// behavior of certain trivial functions?
657+
#if _HAS_MSVC_ATTRIBUTE(intrinsic)
658+
#define _MSVC_INTRINSIC [[msvc::intrinsic]]
659+
#else
660+
#define _MSVC_INTRINSIC
661+
#endif
662+
653663
#undef _HAS_MSVC_ATTRIBUTE
664+
#pragma pop_macro("intrinsic")
654665
#pragma pop_macro("noop_dtor")
655666
#pragma pop_macro("known_semantics")
656667
#pragma pop_macro("msvc")

0 commit comments

Comments
 (0)