[clang] [libcxx] [libc++] Implement LWG3528 (`make_from_tuple` can perform (the equivalent of) a C-style cast) (PR #85263)
Mark de Wever via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 19 11:27:22 PDT 2024
================
@@ -195,6 +195,34 @@ void test_noexcept() {
}
}
+namespace LWG3528 {
+template <class _Tp, class _Tuple, class = std::void_t<>>
+struct can_make_from_tuple : std::false_type {};
+template <class _Tp, class _Tuple>
+struct can_make_from_tuple<
+ _Tp,
+ _Tuple,
+ std::void_t<decltype(std::__make_from_tuple_impl<_Tp>(
+ std::declval<_Tuple>(),
+ std::declval<
+ typename std::__make_tuple_indices< std::tuple_size_v<std::remove_reference_t<_Tuple>>>::type>()))>>
+ : std::true_type {};
+
+struct A {
+ int a;
+};
+struct B : public A {};
+
+// reinterpret_cast
+static_assert(!can_make_from_tuple<int*, std::tuple<A*>>::value);
+
+// const_cast
+static_assert(!can_make_from_tuple<char*, std::tuple<const char*>>::value);
----------------
mordante wrote:
Can you test the `const_cast` with `volatile` and `const volatile`?
I also like to see some tests that valid cases are accepted; then we know `can_make_from_tuple` doesn't just reject everything.
https://github.com/llvm/llvm-project/pull/85263
More information about the cfe-commits
mailing list