Skip to content

Commit 417b08a

Browse files
[libc++] Use __reference_constructs_from_temporary if eligible
Currently, libc++'s `<tuple>` is using the deprecated `__reference_binds_to_temporary` intrinsic. This PR starts to use `__reference_constructs_from_temporary` if possible. It seems that `__reference_constructs_from_temporary` should be used via an internal type traits provided in `<__type_traits/reference_constructs_from_temporary.h>`. But given the old intrinsic was directly used, this PR doesn't switch to the current convention yet. P2255R2 is related. Although the paper indicated that constructors of `tuple` should be deleted in such a case.
1 parent ebe25d8 commit 417b08a

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

libcxx/include/tuple

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,9 @@ class __tuple_leaf {
310310

311311
template <class _Tp>
312312
static _LIBCPP_HIDE_FROM_ABI constexpr bool __can_bind_reference() {
313-
# if __has_keyword(__reference_binds_to_temporary)
313+
# if __has_builtin(__reference_constructs_from_temporary)
314+
return !__reference_constructs_from_temporary(_Hp, _Tp);
315+
# elif __has_keyword(__reference_binds_to_temporary)
314316
return !__reference_binds_to_temporary(_Hp, _Tp);
315317
# else
316318
return true;

libcxx/test/libcxx/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.verify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void F(typename CannotDeduce<std::tuple<Args...>>::type const&) {}
4040

4141

4242
void f() {
43-
#if TEST_HAS_BUILTIN_IDENTIFIER(__reference_binds_to_temporary)
43+
#if TEST_HAS_BUILTIN_IDENTIFIER(__reference_constructs_from_temporary)
4444
// Test that we emit our diagnostic from the library.
4545
// expected-error@tuple:* 8 {{Attempted construction of reference element binds to a temporary whose lifetime has ended}}
4646

libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.pass.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
#include <cassert>
1919
#include "test_macros.h"
2020

21-
#if TEST_HAS_BUILTIN_IDENTIFIER(__reference_binds_to_temporary)
22-
# define ASSERT_REFERENCE_BINDS_TEMPORARY(...) static_assert(__reference_binds_to_temporary(__VA_ARGS__), "")
23-
# define ASSERT_NOT_REFERENCE_BINDS_TEMPORARY(...) static_assert(!__reference_binds_to_temporary(__VA_ARGS__), "")
21+
#if TEST_HAS_BUILTIN_IDENTIFIER(__reference_constructs_from_temporary)
22+
# define ASSERT_REFERENCE_BINDS_TEMPORARY(...) static_assert(__reference_constructs_from_temporary(__VA_ARGS__), "")
23+
# define ASSERT_NOT_REFERENCE_BINDS_TEMPORARY(...) \
24+
static_assert(!__reference_constructs_from_temporary(__VA_ARGS__), "")
2425
#else
25-
# define ASSERT_REFERENCE_BINDS_TEMPORARY(...) static_assert(true, "")
26-
# define ASSERT_NOT_REFERENCE_BINDS_TEMPORARY(...) static_assert(true, "")
26+
# define ASSERT_REFERENCE_BINDS_TEMPORARY(...) static_assert(true, "")
27+
# define ASSERT_NOT_REFERENCE_BINDS_TEMPORARY(...) static_assert(true, "")
2728
#endif
2829

2930
template <class Tp>

0 commit comments

Comments
 (0)