diff options
Diffstat (limited to 'c++/src')
| -rw-r--r-- | c++/src/kj/tuple-test.c++ | 6 | ||||
| -rw-r--r-- | c++/src/kj/tuple.h | 10 |
2 files changed, 11 insertions, 5 deletions
diff --git a/c++/src/kj/tuple-test.c++ b/c++/src/kj/tuple-test.c++ index 979149bd..eeb956fe 100644 --- a/c++/src/kj/tuple-test.c++ +++ b/c++/src/kj/tuple-test.c++ @@ -384,8 +384,7 @@ KJ_TEST("Tuple reference conversion to a derived type uses the conversion operat KJ_EXPECT(&get<0>(constFromExplicitRefs) == &explicitTarget); } -#ifdef __has_builtin -#if __has_builtin(__reference_constructs_from_temporary) +#if KJ_HAS_REFERENCE_CONSTRUCTS_FROM_TEMPORARY KJ_TEST("Tuple conversions do not bind reference elements to temporaries") { // Converting a long to an int creates a temporary, which would die at the end of the // conversion and leave the const reference element dangling. @@ -406,8 +405,7 @@ KJ_TEST("Tuple conversions do not bind reference elements to temporaries") { struct Derived: Base {}; static_assert(!_::ConstructibleFrom<Tuple<const Derived&, int>, Tuple<Base, int>&>); } -#endif -#endif +#endif // KJ_HAS_REFERENCE_CONSTRUCTS_FROM_TEMPORARY KJ_TEST("Tuple reference conversions borrow existing elements") { // Reference elements that bind to the source's own elements remain convertible. diff --git a/c++/src/kj/tuple.h b/c++/src/kj/tuple.h index 77da07bf..f32a4340 100644 --- a/c++/src/kj/tuple.h +++ b/c++/src/kj/tuple.h @@ -115,7 +115,15 @@ struct TupleElement { constexpr inline TupleElement(U&& value): value(pointerSafeSource<T>(kj::fwd<U>(value))) {} }; +#if !defined(_MSC_VER) || defined(__clang__) +// MSVC rejects __reference_constructs_from_temporary as an argument to __has_builtin (C1017), so +// the check must not be evaluated there. #if __has_builtin(__reference_constructs_from_temporary) +#define KJ_HAS_REFERENCE_CONSTRUCTS_FROM_TEMPORARY 1 +#endif +#endif + +#if KJ_HAS_REFERENCE_CONSTRUCTS_FROM_TEMPORARY template <typename T, typename U> concept BindsTemporary = __reference_constructs_from_temporary(T, U&&); #else @@ -123,7 +131,7 @@ template <typename T, typename U> concept BindsTemporary = false; #endif // Concept: T is a reference that, initialized from U&&, would bind to a temporary. Compilers -// without the builtin do not detect this case. +// without the builtin (including MSVC) do not detect this case. template <typename T, typename U> concept TupleElementConstructibleFrom = PointerSafeConstructibleFrom<T, U> && |
