-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[libc++][type_traits] Implements "A type trait to detect reference binding to temporary" #128649
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
philnik777
merged 55 commits into
llvm:main
from
H-G-Hristov:hgh/libcxx/P2255R2-A_type_trait_to_detect_reference_binding_to_temporary
Mar 8, 2025
Merged
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
ab21883
[libc++][type_traits] Implements "A type trait to detect reference bi…
H-G-Hristov 016d341
Address comments
H-G-Hristov 6d25537
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov 5ad9e70
Try to fix CI
H-G-Hristov 93742ac
Fixed modules map condition
H-G-Hristov 9e96a81
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov 49910a0
Fixed formatting
H-G-Hristov fbf6650
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov 8be8079
Try to fix CI
H-G-Hristov f4078bf
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov 17197b3
Try to fix Apple CI
H-G-Hristov 5064494
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov b92ffcb
Try to fix CI
H-G-Hristov cba8f24
Fixed formatting
H-G-Hristov f2c2651
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov a5d6c89
Try to fix Android
H-G-Hristov 8cf7d8a
Merge branch 'hgh/libcxx/P2255R2-A_type_trait_to_detect_reference_bin…
H-G-Hristov 5446525
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov 348efc5
Merge branch 'llvm:main' into hgh/libcxx/P2255R2-A_type_trait_to_dete…
H-G-Hristov 3e46e48
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov 3372938
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov b3f16dd
Addressed review comments
H-G-Hristov 4b10d27
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov 4edecb2
Try to fix CI
H-G-Hristov 665d81b
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov 1d26b11
Merge branch 'hgh/libcxx/P2255R2-A_type_trait_to_detect_reference_bin…
H-G-Hristov c57704c
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov a8de754
Minor tweaks
H-G-Hristov 8cec474
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov d0e0416
Fixed formatting
H-G-Hristov 03706dd
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov 0f34c04
Enable ANDROID
H-G-Hristov 5147b27
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov afc11c6
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov 2c717ea
Updated tests
H-G-Hristov 91f9469
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov 65993fe
Fix C++03
H-G-Hristov 90f3f52
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov 530980f
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
Zingam deb90e9
Fixed type in macro name
H-G-Hristov b9e1bfb
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov 69b6b61
Android NDK r29 support + Release Notes
H-G-Hristov 38b7bc0
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov 994d163
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov 65ebe1e
Updated macros to handle ANDROID clearer
H-G-Hristov a1e77d2
Addressed review comments
H-G-Hristov bd63cfc
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov d192d7f
Addressed review comments
H-G-Hristov 28373d2
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov 0e25010
Fix CI
H-G-Hristov 9342360
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov ae76e7a
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov d50473d
Review comments
H-G-Hristov ad90ac1
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_re…
H-G-Hristov 67274bb
Renamed types
H-G-Hristov 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
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
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
35 changes: 35 additions & 0 deletions
35
libcxx/include/__type_traits/reference_constructs_from_temporary.h
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,35 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef _LIBCPP___TYPE_TRAITS_REFERENCE_CONSTRUCTS_FROM_TEMPORARY_H | ||
#define _LIBCPP___TYPE_TRAITS_REFERENCE_CONSTRUCTS_FROM_TEMPORARY_H | ||
|
||
#include <__config> | ||
#include <__type_traits/integral_constant.h> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
#if _LIBCPP_STD_VER >= 23 && __has_builtin(__reference_constructs_from_temporary) | ||
|
||
template <class _Tp, class _Up> | ||
struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS reference_constructs_from_temporary | ||
: public bool_constant<__reference_constructs_from_temporary(_Tp, _Up)> {}; | ||
|
||
template <class _Tp, class _Up> | ||
_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool reference_constructs_from_temporary_v = | ||
__reference_constructs_from_temporary(_Tp, _Up); | ||
|
||
#endif | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCPP___TYPE_TRAITS_REFERENCE_CONSTRUCTS_FROM_TEMPORARY_H |
35 changes: 35 additions & 0 deletions
35
libcxx/include/__type_traits/reference_converts_from_temporary.h
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,35 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef _LIBCPP___TYPE_TRAITS_REFERENCE_CONVERTS_FROM_TEMPORARY_H | ||
#define _LIBCPP___TYPE_TRAITS_REFERENCE_CONVERTS_FROM_TEMPORARY_H | ||
|
||
#include <__config> | ||
#include <__type_traits/integral_constant.h> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
#if _LIBCPP_STD_VER >= 23 && __has_builtin(__reference_converts_from_temporary) | ||
|
||
template <class _Tp, class _Up> | ||
struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS reference_converts_from_temporary | ||
: public bool_constant<__reference_converts_from_temporary(_Tp, _Up)> {}; | ||
|
||
template <class _Tp, class _Up> | ||
_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool reference_converts_from_temporary_v = | ||
__reference_converts_from_temporary(_Tp, _Up); | ||
|
||
#endif | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCPP___TYPE_TRAITS_REFERENCE_CONVERTS_FROM_TEMPORARY_H |
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
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
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
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
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
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
90 changes: 90 additions & 0 deletions
90
...td/utilities/meta/meta.unary/meta.unary.prop/reference_constructs_from_temporary.pass.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,90 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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++23 | ||
|
||
H-G-Hristov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// These compilers don't support std::reference_converts_from_temporary yet. | ||
// UNSUPPORTED: android, apple-clang-15, apple-clang-16, clang-19.1 | ||
|
||
// <type_traits> | ||
|
||
// template<class T, class U> struct reference_constructs_from_temporary; | ||
|
||
// template<class T, class U> | ||
// constexpr bool reference_constructs_from_temporary_v | ||
// = reference_constructs_from_temporary<T, U>::value; | ||
|
||
#include <cassert> | ||
#include <type_traits> | ||
|
||
#include "common.h" | ||
#include "test_macros.h" | ||
|
||
template <typename T, typename U, bool Expected> | ||
constexpr void test_reference_constructs_from_temporary() { | ||
assert((std::reference_constructs_from_temporary<T, U>::value == Expected)); | ||
assert((std::reference_constructs_from_temporary_v<T, U> == Expected)); | ||
} | ||
|
||
constexpr bool test() { | ||
test_reference_constructs_from_temporary<int&, int&, false>(); | ||
test_reference_constructs_from_temporary<int&, int&, false>(); | ||
test_reference_constructs_from_temporary<int&, int&&, false>(); | ||
|
||
test_reference_constructs_from_temporary<const int&, int&, false>(); | ||
test_reference_constructs_from_temporary<const int&, const int&, false>(); | ||
test_reference_constructs_from_temporary<const int&, int&&, false>(); | ||
|
||
test_reference_constructs_from_temporary<int&, long&, false>(); // doesn't construct | ||
|
||
test_reference_constructs_from_temporary<const int&, long&, true>(); | ||
test_reference_constructs_from_temporary<const int&, long&&, true>(); | ||
test_reference_constructs_from_temporary<int&&, long&, true>(); | ||
|
||
assert((std::is_constructible_v<int&, ConvertsToRef<int, int&>>)); | ||
test_reference_constructs_from_temporary<int&, ConvertsToRef<int, int&>, false>(); | ||
|
||
assert((std::is_constructible_v<int&&, ConvertsToRef<int, int&&>>)); | ||
test_reference_constructs_from_temporary<int&&, ConvertsToRef<int, int&&>, false>(); | ||
|
||
assert((std::is_constructible_v<const int&, ConvertsToRef<int, const int&>>)); | ||
test_reference_constructs_from_temporary<int&&, ConvertsToRef<int, const int&>, false>(); | ||
|
||
assert((std::is_constructible_v<const int&, ConvertsToRef<long, long&>>)); | ||
test_reference_constructs_from_temporary<const int&, ConvertsToRef<long, long&>, true>(); | ||
#ifndef TEST_COMPILER_GCC | ||
test_reference_constructs_from_temporary<const int&, ConvertsToRefPrivate<long, long&>, false>(); | ||
#endif | ||
|
||
// Test that it doesn't accept non-reference types as input. | ||
test_reference_constructs_from_temporary<int, long, false>(); | ||
|
||
test_reference_constructs_from_temporary<const int&, long, true>(); | ||
|
||
// Additional checks | ||
test_reference_constructs_from_temporary<const Base&, Derived, true>(); | ||
test_reference_constructs_from_temporary<int&&, int, true>(); | ||
test_reference_constructs_from_temporary<const int&, int, true>(); | ||
test_reference_constructs_from_temporary<int&&, int&&, false>(); | ||
test_reference_constructs_from_temporary<const int&, int&&, false>(); | ||
test_reference_constructs_from_temporary<int&&, long&&, true>(); | ||
test_reference_constructs_from_temporary<int&&, long, true>(); | ||
|
||
test_reference_constructs_from_temporary<int&, ExplicitConversionRef, false>(); | ||
test_reference_constructs_from_temporary<const int&, ExplicitConversionRef, false>(); | ||
test_reference_constructs_from_temporary<int&&, ExplicitConversionRvalueRef, false>(); | ||
|
||
return true; | ||
} | ||
|
||
int main(int, char**) { | ||
test(); | ||
static_assert(test()); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Zingam It looks like you forgot to add tests for the
_LIBCPP_NO_SPECIALIZATIONS
annotations. Could you add them in a follow-up PR?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'll do it.