Skip to content

[libc++] Use __reference_constructs_from_temporary if eligible #141916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,10 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool reference_constructs_from_tempo
#if __has_builtin(__reference_constructs_from_temporary)
template <class _Tp, class _Up>
inline const bool __reference_constructs_from_temporary_v = __reference_constructs_from_temporary(_Tp, _Up);
#elif __has_builtin(__reference_binds_to_temporary)
// TODO: Remove this once all support compilers have __reference_constructs_from_temporary implemented.
template <class _Tp, class _Up>
inline const bool __reference_constructs_from_temporary_v = __reference_binds_to_temporary(_Tp, _Up);
#else
// TODO: Remove this once https://github.com/llvm/llvm-project/issues/111477 no longer affects supported compilers.
// TODO(LLVM 22): Remove this as all support compilers should have __reference_constructs_from_temporary implemented.
template <class _Tp, class _Up>
inline const bool __reference_constructs_from_temporary_v = false;
inline const bool __reference_constructs_from_temporary_v = __reference_binds_to_temporary(_Tp, _Up);
#endif

_LIBCPP_END_NAMESPACE_STD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,7 @@ template <class T> struct CannotDeduce {
template <class ...Args>
void F(typename CannotDeduce<std::tuple<Args...>>::type const&) {}

#if TEST_HAS_BUILTIN(__reference_constructs_from_temporary)
# define TEST_HAS_REFERENCE_BINDING_TRAIT 1
#elif TEST_HAS_BUILTIN(__reference_binds_to_temporary)
# define TEST_HAS_REFERENCE_BINDING_TRAIT 1
#else
# define TEST_HAS_REFERENCE_BINDING_TRAIT 0
#endif

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

Expand Down Expand Up @@ -80,8 +71,4 @@ void f() {
std::tuple<std::string &&> t2("hello"); // expected-note {{requested here}}
std::tuple<std::string &&> t3(std::allocator_arg, alloc, "hello"); // expected-note {{requested here}}
}
#else
#error force failure
// expected-error@-1 {{force failure}}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
# define ASSERT_REFERENCE_BINDS_TEMPORARY(...) static_assert(__reference_constructs_from_temporary(__VA_ARGS__), "")
# define ASSERT_NOT_REFERENCE_BINDS_TEMPORARY(...) \
static_assert(!__reference_constructs_from_temporary(__VA_ARGS__), "")
#elif TEST_HAS_BUILTIN(__reference_binds_to_temporary)
#else
// TODO(LLVM 22): Remove this as all support compilers should have __reference_constructs_from_temporary implemented.
# define ASSERT_REFERENCE_BINDS_TEMPORARY(...) static_assert(__reference_binds_to_temporary(__VA_ARGS__), "")
# define ASSERT_NOT_REFERENCE_BINDS_TEMPORARY(...) static_assert(!__reference_binds_to_temporary(__VA_ARGS__), "")
#else
# define ASSERT_REFERENCE_BINDS_TEMPORARY(...) static_assert(true, "")
# define ASSERT_NOT_REFERENCE_BINDS_TEMPORARY(...) static_assert(true, "")
#endif

template <class Tp>
Expand Down
Loading