-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[libc++][tuple.apply] Implement P2255R2 make_from_tuple part. #152867
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
Open
yronglin
wants to merge
9
commits into
llvm:main
Choose a base branch
from
yronglin:make_from_tuple_temp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7d345a5
[libc++] Implement std::make_from_tuple mandates: If tuple_size_v<rem…
yronglin 6312ab0
Address review comments
yronglin 01fe546
Fix test
yronglin 21b69d4
XFAIL test in clang-module-build, because the diagnostic in tuple std…
yronglin 59baea1
Only disable c++17 clang-modules-build
yronglin 4e73566
Guard with _LIBCPP_STD_VER >= 23 and update test
yronglin 3fa2b50
Merge branch 'main' into make_from_tuple_temp
yronglin 3caf149
Remove xfail
yronglin 65472f9
Check compiler implemented __reference_constructs_from_temporary
yronglin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1432,6 +1432,7 @@ inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, | |||||||||||||
enable_if_t<is_constructible_v<_Tp, decltype(std::get<_Idx>(std::forward<_Tuple>(__t)))...>> * = nullptr) | ||||||||||||||
_LIBCPP_NOEXCEPT_RETURN(_Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...)) | ||||||||||||||
#endif // _LIBCPP_STD_VER >= 20 | ||||||||||||||
#undef _LIBCPP_NOEXCEPT_RETURN | ||||||||||||||
|
||||||||||||||
template <class _Tp, class _Tuple, | ||||||||||||||
class _Seq = make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>, class = void> | ||||||||||||||
|
@@ -1451,10 +1452,17 @@ template <class _Tp, class _Tuple> | |||||||||||||
#else | ||||||||||||||
template <class _Tp, class _Tuple, class = enable_if_t<__can_make_from_tuple<_Tp, _Tuple>>> // strengthen | ||||||||||||||
#endif // _LIBCPP_STD_VER >= 20 | ||||||||||||||
|
||||||||||||||
inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp make_from_tuple(_Tuple&& __t) | ||||||||||||||
_LIBCPP_NOEXCEPT_RETURN(std::__make_from_tuple_impl<_Tp>( | ||||||||||||||
std::forward<_Tuple>(__t), make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>())) | ||||||||||||||
# undef _LIBCPP_NOEXCEPT_RETURN | ||||||||||||||
noexcept(noexcept(std::__make_from_tuple_impl<_Tp>(std::forward<_Tuple>(__t), | ||||||||||||||
make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>()))) { | ||||||||||||||
if constexpr (tuple_size_v<remove_reference_t<_Tuple>> == 1) { | ||||||||||||||
static_assert(!__reference_constructs_from_temporary_v<_Tp, decltype(std::get<0>(std::declval<_Tuple>()))>, | ||||||||||||||
"Attempted construction of reference element binds to a temporary whose lifetime has ended"); | ||||||||||||||
} | ||||||||||||||
yronglin marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+1460
to
+1463
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No... this will break |
||||||||||||||
return std::__make_from_tuple_impl<_Tp>( | ||||||||||||||
std::forward<_Tuple>(__t), make_index_sequence<tuple_size_v<remove_reference_t<_Tuple>>>()); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
# endif // _LIBCPP_STD_VER >= 17 | ||||||||||||||
|
||||||||||||||
|
34 changes: 34 additions & 0 deletions
34
libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.verify.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// REQUIRES: std-at-least-c++17 | ||
yronglin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// No diagnostic gets emitted when we build with modules. | ||
// XFAIL: (c++17 && clang-modules-build) | ||
|
||
// <tuple> | ||
|
||
// template <class T, class Tuple> constexpr T make_from_tuple(Tuple&&); | ||
// Mandates: If tuple_size_v<remove_reference_t<Tuple>> is 1, then reference_constructs_from_temporary_v<T, decltype(get<0>(declval<Tuple>()))> is false. | ||
|
||
#include <tuple> | ||
#include <utility> | ||
|
||
#include "test_macros.h" | ||
|
||
void test() { | ||
// expected-error@*:* {{static assertion failed}} | ||
|
||
// Turns to an error since C++26 (Disallow Binding a Returned Glvalue to a Temporary https://wg21.link/P2748R5). | ||
#if TEST_STD_VER >= 26 | ||
// expected-error@tuple:* {{returning reference to local temporary object}} | ||
#else | ||
// expected-warning@tuple:* {{returning reference to local temporary object}} | ||
#endif | ||
std::ignore = std::make_from_tuple<const int&>(std::tuple<char>{}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.