auto_diagnostic_group d;
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 2344b5eea00..396a9f6b44e 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12007,6 +12007,12 @@ trait_expr_value (cp_trait_kind kind, tree
type1, tree type2)
case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
return is_nothrow_xible (INIT_EXPR, type1, type2);
+ case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
+ return reference_from_temporary (type1, type2,
/*direct_init=*/true);
+
+ case CPTK_REF_CONVERTS_FROM_TEMPORARY:
+ return reference_from_temporary (type1, type2,
/*direct_init=*/false);
+
default:
gcc_unreachable ();
return false;
@@ -12088,6 +12094,8 @@ finish_trait_expr (location_t loc,
cp_trait_kind kind, tree type1, tree type2)
case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
case CPTK_IS_NOTHROW_ASSIGNABLE:
case CPTK_IS_NOTHROW_CONSTRUCTIBLE:
+ case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY:
+ case CPTK_REF_CONVERTS_FROM_TEMPORARY:
if (!check_trait_type (type1)
|| !check_trait_type (type2))
return error_mark_node;
diff --git
a/gcc/testsuite/g++.dg/ext/reference_constructs_from_temporary1.C
b/gcc/testsuite/g++.dg/ext/reference_constructs_from_temporary1.C
new file mode 100644
index 00000000000..76de905a35d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/reference_constructs_from_temporary1.C
@@ -0,0 +1,214 @@
+// P2255R2
+// PR c++/104477
+// { dg-do compile { target c++11 } }
+
+#define SA(X) static_assert((X),#X)
+
+struct A { A(); };
+struct B { operator A(); };
+struct C { explicit C(); };
+struct D { explicit operator A(); };
+struct E { explicit operator A&(); };
+struct F { explicit operator A&&(); };
+// Could use a class template with explicit(bool), but then this
would need
+// C++20.
+struct G {
+ operator int();
+ explicit operator int&&();
+};
+struct G2 {
+ explicit operator int();
+ operator int&&();
+};
+struct H {
+ operator int();
+ explicit operator int&();
+};
+struct H2 {
+ explicit operator int();
+ operator int&();
+};
+
+struct Base { };
+struct Der : Base { };
+
+template<typename T, typename RT>
+struct morph {
+ mutable T val{};
+ operator RT() const { return static_cast<RT>(val); }
+};
+
+template<typename T> using id = T;
+
+// Built-in types.
+SA(!__reference_constructs_from_temporary(int, int));
+SA(!__reference_constructs_from_temporary(int&, void));
+SA(!__reference_constructs_from_temporary(int&, const void));
+SA(!__reference_constructs_from_temporary(int&, volatile void));
+SA(!__reference_constructs_from_temporary(int&, const volatile void));
+SA(!__reference_constructs_from_temporary(void, void));
+SA(!__reference_constructs_from_temporary(void, int));
+SA(!__reference_constructs_from_temporary(int&, int));
+SA(!__reference_constructs_from_temporary(int&, int&));
+SA(!__reference_constructs_from_temporary(int&, int&&));
+SA(!__reference_constructs_from_temporary(int&, long));
+// non-const lvalue reference to type 'int' cannot bind to a value of
unrelated type 'long'
+SA(!__reference_constructs_from_temporary(int&, long&));
+SA(!__reference_constructs_from_temporary(int&, long&&));
+SA( __reference_constructs_from_temporary(const int&, int));
+SA(!__reference_constructs_from_temporary(const int&, int&));
+SA(!__reference_constructs_from_temporary(const int&, const int&));
+SA(!__reference_constructs_from_temporary(const int&, int&&));
+SA( __reference_constructs_from_temporary(const int&, long));
+SA( __reference_constructs_from_temporary(const int&, long&));
+SA( __reference_constructs_from_temporary(const int&, long&&));
+SA( __reference_constructs_from_temporary(int&&, int));
+SA(!__reference_constructs_from_temporary(int&&, int&));
+SA(!__reference_constructs_from_temporary(int&&, int&&));
+SA( __reference_constructs_from_temporary(int&&, long));
+SA( __reference_constructs_from_temporary(int&&, long&));
+SA( __reference_constructs_from_temporary(int&&, long&&));
+SA(!__reference_constructs_from_temporary(unsigned int&, double));
+SA(!__reference_constructs_from_temporary(volatile int&, int));
+SA(!__reference_constructs_from_temporary(const volatile int&, int));
+SA(!__reference_constructs_from_temporary(volatile int&, int&));
+SA(!__reference_constructs_from_temporary(const volatile int&, int&));
+SA(!__reference_constructs_from_temporary(volatile int&, int&&));
+SA(!__reference_constructs_from_temporary(const volatile int&, int&&));
+
+// Classes.
+SA(!__reference_constructs_from_temporary(A, A));
+// A& r(A{}); doesn't construct.
+SA(!__reference_constructs_from_temporary(A&, A));
+SA(!__reference_constructs_from_temporary(A&, A&));
+SA(!__reference_constructs_from_temporary(A&, A&&));
+// Here we get const struct A & r = (const struct A &) &D.2414;
+SA( __reference_constructs_from_temporary(const A&, A));
+SA(!__reference_constructs_from_temporary(const A&, A&));
+SA(!__reference_constructs_from_temporary(const A&, const A&));
+SA(!__reference_constructs_from_temporary(const A&, A&&));
+// Here we get struct A & r = (struct A &) &D.2439;
+SA( __reference_constructs_from_temporary(A&&, A));
+SA(!__reference_constructs_from_temporary(A&&, A&));
+SA(!__reference_constructs_from_temporary(A&&, const A&));
+SA(!__reference_constructs_from_temporary(A&&, A&&));
+
+SA(!__reference_constructs_from_temporary(A, B));
+SA(!__reference_constructs_from_temporary(A&, B));
+SA(!__reference_constructs_from_temporary(A&, B&));
+SA(!__reference_constructs_from_temporary(A&, const B&));
+SA(!__reference_constructs_from_temporary(A&, B&&));
+SA( __reference_constructs_from_temporary(const A&, B));
+SA( __reference_constructs_from_temporary(const A&, B&));
+// Doesn't construct, so it's false.
+SA(!__reference_constructs_from_temporary(const A&, const B&));
+SA( __reference_constructs_from_temporary(const A&, B&&));
+SA( __reference_constructs_from_temporary(A&&, B));
+SA( __reference_constructs_from_temporary(A&&, B&));
+SA(!__reference_constructs_from_temporary(A&&, const B&));
+SA( __reference_constructs_from_temporary(A&&, B&&));
+
+SA(!__reference_constructs_from_temporary(const A&, C));
+SA(!__reference_constructs_from_temporary(const A&, C&));
+
+// Doesn't construct, so it's false.
+SA(!__reference_constructs_from_temporary(int&, morph<int, int>));
+// Here we get
+// const int & r2 = D.2580 = morph<int, int>::operator int
+// (&TARGET_EXPR <D.2578, {.val=0}>); (const int &) &D.2580;
+SA( __reference_constructs_from_temporary(const int&, morph<int, int>));
+SA(!__reference_constructs_from_temporary(int&, morph<int, int&>));
+SA(!__reference_constructs_from_temporary(int&, morph<int, const
int&>));
+SA(!__reference_constructs_from_temporary(int&, morph<int, int&&>));
+SA( __reference_constructs_from_temporary(const int&, morph<long,
long&>));
+
+// These are like const C& c(cref); so the explicit ctor C isn't a
problem
+// even in copy-init context. const C& r = {}; would be a different
story.
+SA(!__reference_constructs_from_temporary(C, C));
+SA(!__reference_constructs_from_temporary(C&, C));
+SA(!__reference_constructs_from_temporary(C&, C&));
+SA(!__reference_constructs_from_temporary(C&, C&&));
+SA( __reference_constructs_from_temporary(const C&, C));
+SA(!__reference_constructs_from_temporary(const C&, C&));
+SA(!__reference_constructs_from_temporary(const C&, const C&));
+SA(!__reference_constructs_from_temporary(const C&, C&&));
+SA( __reference_constructs_from_temporary(C&&, C));
+SA(!__reference_constructs_from_temporary(C&&, C&));
+SA(!__reference_constructs_from_temporary(C&&, const C&));
+SA(!__reference_constructs_from_temporary(C&&, C&&));
+
+// These are all false ultimately because of CWG 2267, which we
implement.
+SA(!__reference_constructs_from_temporary(A, D));
+SA(!__reference_constructs_from_temporary(A&, D));
+SA(!__reference_constructs_from_temporary(A&, D&));
+SA(!__reference_constructs_from_temporary(A&, const D&));
+SA(!__reference_constructs_from_temporary(A&, D&&));
+SA(!__reference_constructs_from_temporary(const A&, D));
+SA(!__reference_constructs_from_temporary(const A&, D&));
+SA(!__reference_constructs_from_temporary(const A&, const D&));
+SA(!__reference_constructs_from_temporary(const A&, D&&));
+SA(!__reference_constructs_from_temporary(A&&, D));
+SA(!__reference_constructs_from_temporary(A&&, D&));
+SA(!__reference_constructs_from_temporary(A&&, const D&));
+SA(!__reference_constructs_from_temporary(A&&, D&&));
+
+SA(!__reference_constructs_from_temporary(A, E));
+/* A& a1(E{}); compiles, but A& a2 = E{}; doesn't.
+ With the former, we get A& a = E::operator A& (&TARGET_EXPR
<D.2715, {}>)
+ so we're not binding the reference to a temporary, although there is
+ a temporary involved. So the result is false in both copy- and
direct-
+ init, albeit for different reasons! */
+SA(!__reference_constructs_from_temporary(A&, E));
+// A& a = E::operator A& ((struct E *) r)); copy-init doesn't compile.
+SA(!__reference_constructs_from_temporary(A&, E&));
+SA(!__reference_constructs_from_temporary(A&, const E&));
+SA(!__reference_constructs_from_temporary(A&, E&&));
+// direct-init:
+// const A& a = (const struct A &) E::operator A& (&TARGET_EXPR
<D.2720, {}>)
+SA(!__reference_constructs_from_temporary(const A&, E));
+SA(!__reference_constructs_from_temporary(const A&, E&));
+SA(!__reference_constructs_from_temporary(const A&, const E&));
+SA(!__reference_constructs_from_temporary(const A&, E&&));
+SA(!__reference_constructs_from_temporary(A&&, E));
+SA(!__reference_constructs_from_temporary(A&&, E&));
+SA(!__reference_constructs_from_temporary(A&&, const E&));
+SA(!__reference_constructs_from_temporary(A&&, E&&));
+
+SA(!__reference_constructs_from_temporary(A, F));
+// A& a1(F{}); and A& a2 = F{}; both invalid.
+SA(!__reference_constructs_from_temporary(A&, F));
+SA(!__reference_constructs_from_temporary(A&, F&));
+SA(!__reference_constructs_from_temporary(A&, const F&));
+SA(!__reference_constructs_from_temporary(A&, F&&));
+SA(!__reference_constructs_from_temporary(const A&, F));
+SA(!__reference_constructs_from_temporary(const A&, F&));
+SA(!__reference_constructs_from_temporary(const A&, const F&));
+SA(!__reference_constructs_from_temporary(const A&, F&&));
+SA(!__reference_constructs_from_temporary(A&&, F));
+SA(!__reference_constructs_from_temporary(A&&, F&));
+SA(!__reference_constructs_from_temporary(A&&, const F&));
+SA(!__reference_constructs_from_temporary(A&&, F&&));
+
+/* This is where _converts_ and _constructs_ will differ:
+ in direct-init we use G::operator int&& (no temporary),
+ but in copy-init we use G::operator int, where a temporary is created
+ to be bound to int&&. */
+SA(!__reference_constructs_from_temporary(int&&, G));
+// Similar to the previous one.
+SA(!__reference_constructs_from_temporary(const int&, H));
+/* And here I've switched the explicit-ness. In both copy- and
direct-init
+ we call operator int&, so no temporary. */
+SA(!__reference_constructs_from_temporary(int&&, G2));
+SA(!__reference_constructs_from_temporary(const int&, H2));
+
+SA(!__reference_constructs_from_temporary(const Base&, Der));
+
+// This fails because std::is_constructible_v<int&&, id<int[3]>> is
false.
+SA(!__reference_constructs_from_temporary(int&&, id<int[3]>));
+
+// Arrays.
+SA(!__reference_constructs_from_temporary(int, int[]));
+SA(!__reference_constructs_from_temporary(int[], int[]));
+SA(!__reference_constructs_from_temporary(int&, int[]));
+SA(!__reference_constructs_from_temporary(int&&, int[]));
+SA(!__reference_constructs_from_temporary(const int&, int[]));
diff --git
a/gcc/testsuite/g++.dg/ext/reference_converts_from_temporary1.C
b/gcc/testsuite/g++.dg/ext/reference_converts_from_temporary1.C
new file mode 100644
index 00000000000..90196c38742
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/reference_converts_from_temporary1.C
@@ -0,0 +1,214 @@
+// P2255R2
+// PR c++/104477
+// { dg-do compile { target c++11 } }
+
+#define SA(X) static_assert((X),#X)
+
+struct A { A(); };
+struct B { operator A(); };
+struct C { explicit C(); };
+struct D { explicit operator A(); };
+struct E { explicit operator A&(); };
+struct F { explicit operator A&&(); };
+// Could use a class template with explicit(bool), but then this
would need
+// C++20.
+struct G {
+ operator int();
+ explicit operator int&&();
+};
+struct G2 {
+ explicit operator int();
+ operator int&&();
+};
+struct H {
+ operator int();
+ explicit operator int&();
+};
+struct H2 {
+ explicit operator int();
+ operator int&();
+};
+
+struct Base { };
+struct Der : Base { };
+
+template<typename T, typename RT>
+struct morph {
+ mutable T val{};
+ operator RT() const { return static_cast<RT>(val); }
+};
+
+template<typename T> using id = T;
+
+// Built-in types.
+SA(!__reference_converts_from_temporary(int, int));
+SA(!__reference_converts_from_temporary(int&, void));
+SA(!__reference_converts_from_temporary(int&, const void));
+SA(!__reference_converts_from_temporary(int&, volatile void));
+SA(!__reference_converts_from_temporary(int&, const volatile void));
+SA(!__reference_converts_from_temporary(void, void));
+SA(!__reference_converts_from_temporary(void, int));
+SA(!__reference_converts_from_temporary(int&, int));
+SA(!__reference_converts_from_temporary(int&, int&));
+SA(!__reference_converts_from_temporary(int&, int&&));
+SA(!__reference_converts_from_temporary(int&, long));
+// non-const lvalue reference to type 'int' cannot bind to a value of
unrelated type 'long'
+SA(!__reference_converts_from_temporary(int&, long&));
+SA(!__reference_converts_from_temporary(int&, long&&));
+SA( __reference_converts_from_temporary(const int&, int));
+SA(!__reference_converts_from_temporary(const int&, int&));
+SA(!__reference_converts_from_temporary(const int&, const int&));
+SA(!__reference_converts_from_temporary(const int&, int&&));
+SA( __reference_converts_from_temporary(const int&, long));
+SA( __reference_converts_from_temporary(const int&, long&));
+SA( __reference_converts_from_temporary(const int&, long&&));
+SA( __reference_converts_from_temporary(int&&, int));
+SA(!__reference_converts_from_temporary(int&&, int&));
+SA(!__reference_converts_from_temporary(int&&, int&&));
+SA( __reference_converts_from_temporary(int&&, long));
+SA( __reference_converts_from_temporary(int&&, long&));
+SA( __reference_converts_from_temporary(int&&, long&&));
+SA(!__reference_converts_from_temporary(unsigned int&, double));
+SA(!__reference_converts_from_temporary(volatile int&, int));
+SA(!__reference_converts_from_temporary(const volatile int&, int));
+SA(!__reference_converts_from_temporary(volatile int&, int&));
+SA(!__reference_converts_from_temporary(const volatile int&, int&));
+SA(!__reference_converts_from_temporary(volatile int&, int&&));
+SA(!__reference_converts_from_temporary(const volatile int&, int&&));
+
+// Classes.
+SA(!__reference_converts_from_temporary(A, A));
+// A& r(A{}); doesn't construct.
+SA(!__reference_converts_from_temporary(A&, A));
+SA(!__reference_converts_from_temporary(A&, A&));
+SA(!__reference_converts_from_temporary(A&, A&&));
+// Here we get const struct A & r = (const struct A &) &D.2414;
+SA( __reference_converts_from_temporary(const A&, A));
+SA(!__reference_converts_from_temporary(const A&, A&));
+SA(!__reference_converts_from_temporary(const A&, const A&));
+SA(!__reference_converts_from_temporary(const A&, A&&));
+// Here we get struct A & r = (struct A &) &D.2439;
+SA( __reference_converts_from_temporary(A&&, A));
+SA(!__reference_converts_from_temporary(A&&, A&));
+SA(!__reference_converts_from_temporary(A&&, const A&));
+SA(!__reference_converts_from_temporary(A&&, A&&));
+
+SA(!__reference_converts_from_temporary(A, B));
+SA(!__reference_converts_from_temporary(A&, B));
+SA(!__reference_converts_from_temporary(A&, B&));
+SA(!__reference_converts_from_temporary(A&, const B&));
+SA(!__reference_converts_from_temporary(A&, B&&));
+SA( __reference_converts_from_temporary(const A&, B));
+SA( __reference_converts_from_temporary(const A&, B&));
+// Doesn't construct, so it's false.
+SA(!__reference_converts_from_temporary(const A&, const B&));
+SA( __reference_converts_from_temporary(const A&, B&&));
+SA( __reference_converts_from_temporary(A&&, B));
+SA( __reference_converts_from_temporary(A&&, B&));
+SA(!__reference_converts_from_temporary(A&&, const B&));
+SA( __reference_converts_from_temporary(A&&, B&&));
+
+SA(!__reference_converts_from_temporary(const A&, C));
+SA(!__reference_converts_from_temporary(const A&, C&));
+
+// Doesn't construct, so it's false.
+SA(!__reference_converts_from_temporary(int&, morph<int, int>));
+// Here we get
+// const int & r2 = D.2580 = morph<int, int>::operator int
+// (&TARGET_EXPR <D.2578, {.val=0}>); (const int &) &D.2580;
+SA( __reference_converts_from_temporary(const int&, morph<int, int>));
+SA(!__reference_converts_from_temporary(int&, morph<int, int&>));
+SA(!__reference_converts_from_temporary(int&, morph<int, const int&>));
+SA(!__reference_converts_from_temporary(int&, morph<int, int&&>));
+SA( __reference_converts_from_temporary(const int&, morph<long,
long&>));
+
+// These are like const C& c(cref); so the explicit ctor C isn't a
problem
+// even in copy-init context. const C& r = {}; would be a different
story.
+SA(!__reference_converts_from_temporary(C, C));
+SA(!__reference_converts_from_temporary(C&, C));
+SA(!__reference_converts_from_temporary(C&, C&));
+SA(!__reference_converts_from_temporary(C&, C&&));
+SA( __reference_converts_from_temporary(const C&, C));
+SA(!__reference_converts_from_temporary(const C&, C&));
+SA(!__reference_converts_from_temporary(const C&, const C&));
+SA(!__reference_converts_from_temporary(const C&, C&&));
+SA( __reference_converts_from_temporary(C&&, C));
+SA(!__reference_converts_from_temporary(C&&, C&));
+SA(!__reference_converts_from_temporary(C&&, const C&));
+SA(!__reference_converts_from_temporary(C&&, C&&));
+
+// These are all false ultimately because of CWG 2267, which we
implement.
+SA(!__reference_converts_from_temporary(A, D));
+SA(!__reference_converts_from_temporary(A&, D));
+SA(!__reference_converts_from_temporary(A&, D&));
+SA(!__reference_converts_from_temporary(A&, const D&));
+SA(!__reference_converts_from_temporary(A&, D&&));
+SA(!__reference_converts_from_temporary(const A&, D));
+SA(!__reference_converts_from_temporary(const A&, D&));
+SA(!__reference_converts_from_temporary(const A&, const D&));
+SA(!__reference_converts_from_temporary(const A&, D&&));
+SA(!__reference_converts_from_temporary(A&&, D));
+SA(!__reference_converts_from_temporary(A&&, D&));
+SA(!__reference_converts_from_temporary(A&&, const D&));
+SA(!__reference_converts_from_temporary(A&&, D&&));
+
+SA(!__reference_converts_from_temporary(A, E));
+/* A& a1(E{}); compiles, but A& a2 = E{}; doesn't.
+ With the former, we get A& a = E::operator A& (&TARGET_EXPR
<D.2715, {}>)
+ so we're not binding the reference to a temporary, although there is
+ a temporary involved. So the result is false in both copy- and
direct-
+ init, albeit for different reasons! */
+SA(!__reference_converts_from_temporary(A&, E));
+// A& a = E::operator A& ((struct E *) r)); copy-init doesn't compile.
+SA(!__reference_converts_from_temporary(A&, E&));
+SA(!__reference_converts_from_temporary(A&, const E&));
+SA(!__reference_converts_from_temporary(A&, E&&));
+// direct-init:
+// const A& a = (const struct A &) E::operator A& (&TARGET_EXPR
<D.2720, {}>)
+SA(!__reference_converts_from_temporary(const A&, E));
+SA(!__reference_converts_from_temporary(const A&, E&));
+SA(!__reference_converts_from_temporary(const A&, const E&));
+SA(!__reference_converts_from_temporary(const A&, E&&));
+SA(!__reference_converts_from_temporary(A&&, E));
+SA(!__reference_converts_from_temporary(A&&, E&));
+SA(!__reference_converts_from_temporary(A&&, const E&));
+SA(!__reference_converts_from_temporary(A&&, E&&));
+
+SA(!__reference_converts_from_temporary(A, F));
+// A& a1(F{}); and A& a2 = F{}; both invalid.
+SA(!__reference_converts_from_temporary(A&, F));
+SA(!__reference_converts_from_temporary(A&, F&));
+SA(!__reference_converts_from_temporary(A&, const F&));
+SA(!__reference_converts_from_temporary(A&, F&&));
+SA(!__reference_converts_from_temporary(const A&, F));
+SA(!__reference_converts_from_temporary(const A&, F&));
+SA(!__reference_converts_from_temporary(const A&, const F&));
+SA(!__reference_converts_from_temporary(const A&, F&&));
+SA(!__reference_converts_from_temporary(A&&, F));
+SA(!__reference_converts_from_temporary(A&&, F&));
+SA(!__reference_converts_from_temporary(A&&, const F&));
+SA(!__reference_converts_from_temporary(A&&, F&&));
+
+/* This is where _converts_ and _constructs_ will differ:
+ in direct-init we use G::operator int&& (no temporary),
+ but in copy-init we use G::operator int, where a temporary is created
+ to be bound to int&&. */
+SA( __reference_converts_from_temporary(int&&, G));
+// Similar to the previous one.
+SA( __reference_converts_from_temporary(const int&, H));
+/* And here I've switched the explicit-ness. In both copy- and
direct-init
+ we call operator int&, so no temporary. */
+SA(!__reference_converts_from_temporary(int&&, G2));
+SA(!__reference_converts_from_temporary(const int&, H2));
+
+SA(!__reference_converts_from_temporary(const Base&, Der));
+
+// This fails because std::is_constructible_v<int&&, id<int[3]>> is
false.
+SA(!__reference_converts_from_temporary(int&&, id<int[3]>));
+
+// Arrays.
+SA(!__reference_converts_from_temporary(int, int[]));
+SA(!__reference_converts_from_temporary(int[], int[]));
+SA(!__reference_converts_from_temporary(int&, int[]));
+SA(!__reference_converts_from_temporary(int&&, int[]));
+SA(!__reference_converts_from_temporary(const int&, int[]));
diff --git a/libstdc++-v3/include/std/type_traits
b/libstdc++-v3/include/std/type_traits
index 2572d8edd69..bbeb049e1f9 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -3508,6 +3508,45 @@ template<typename _Ret, typename _Fn,
typename... _Args>
template<typename _Tp>
inline constexpr bool is_scoped_enum_v =
is_scoped_enum<_Tp>::value;
+#define __cpp_lib_reference_from_temporary 202202L
+
+ /// True if _Tp is a reference type, a _Up value can be bound to
_Tp in
+ /// direct-initialization, and a temporary object would be bound to
+ /// the reference, false otherwise.
+ /// @since C++23
+ template<typename _Tp, typename _Up>
+ struct reference_constructs_from_temporary
+ : public
__bool_constant<__reference_constructs_from_temporary(_Tp, _Up)>
+ {
+
static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{})
+ && std::__is_complete_or_unbounded(__type_identity<_Up>{}),
+ "template argument must be a complete class or an unbounded array");
+ };
+
+ /// True if _Tp is a reference type, a _Up value can be bound to
_Tp in
+ /// copy-initialization, and a temporary object would be bound to
+ /// the reference, false otherwise.
+ /// @since C++23
+ template<typename _Tp, typename _Up>
+ struct reference_converts_from_temporary
+ : public __bool_constant<__reference_converts_from_temporary(_Tp,
_Up)>
+ {
+
static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{})
+ && std::__is_complete_or_unbounded(__type_identity<_Up>{}),
+ "template argument must be a complete class or an unbounded array");
+ };
+
+ /// @ingroup variable_templates
+ /// @since C++23
+ template<typename _Tp, typename _Up>
+ inline constexpr bool reference_constructs_from_temporary_v
+ = reference_constructs_from_temporary<_Tp, _Up>::value;
+
+ /// @ingroup variable_templates
+ /// @since C++23
+ template<typename _Tp, typename _Up>
+ inline constexpr bool reference_converts_from_temporary_v
+ = reference_converts_from_temporary<_Tp, _Up>::value;
#endif // C++23
#if _GLIBCXX_HAVE_IS_CONSTANT_EVALUATED
diff --git a/libstdc++-v3/include/std/version
b/libstdc++-v3/include/std/version
index 22280e1a349..5edca2f3007 100644
--- a/libstdc++-v3/include/std/version
+++ b/libstdc++-v3/include/std/version
@@ -300,10 +300,11 @@
#endif
#if __cplusplus > 202002L
-// c++2b
+// c++23
#define __cpp_lib_byteswap 202110L
#define __cpp_lib_constexpr_typeinfo 202106L
#define __cpp_lib_is_scoped_enum 202011L
+#define __cpp_lib_reference_from_temporary 202202L
#if _GLIBCXX_HOSTED
#define __cpp_lib_adaptor_iterator_pair_constructor 202106L
@@ -335,7 +336,7 @@
#define __cpp_lib_to_underlying 202102L
#define __cpp_lib_unreachable 202202L
#endif
-#endif // C++2b
+#endif // C++23
#endif // C++20
#endif // C++17
#endif // C++14
diff --git
a/libstdc++-v3/testsuite/20_util/reference_from_temporary/value.cc
b/libstdc++-v3/testsuite/20_util/reference_from_temporary/value.cc
new file mode 100644
index 00000000000..2f62e54d46d
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/reference_from_temporary/value.cc
@@ -0,0 +1,110 @@
+// Copyright (C) 2022 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++23" }
+// { dg-do compile { target c++23 } }
+
+#include <type_traits>
+#include <testsuite_tr1.h>
+
+#ifndef __cpp_lib_reference_from_temporary
+# error "Feature test macro for reference_from_temporary is missing
in <version>"
+#elif __cpp_lib_reference_from_temporary < 202202L
+# error "Feature test macro for reference_from_temporary has wrong
value in <version>"
+#endif
+
+void test01()
+{
+ using std::reference_constructs_from_temporary;
+ using std::reference_converts_from_temporary;
+ using namespace __gnu_test;
+
+ struct A { A(); };
+
+ struct B {
+ operator int();
+ explicit operator int&&();
+ };
+
+ struct C {
+ operator int();
+ explicit operator int&();
+ };
+
+ static_assert(test_property<reference_constructs_from_temporary,
int, int>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary,
int&, void>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary,
int&, const volatile void>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary,
void, void>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary,
int&, int>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary,
int&, int&>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary,
int&, int&&>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary,
int&, long>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary,
int&, long&>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary,
int&, long&&>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary,
const int&, int>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary,
const int&, int&>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary,
const int&, int&&>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary,
const int&, long>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary,
const int&, long&>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary,
const int&, long&&>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary,
int&&, int>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary,
int&&, int&>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary,
int&&, int&&>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary,
int&&, long>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary,
int&&, long&>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary,
int&&, long&&>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary,
const A&, A>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary,
const A&, A&&>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary,
A&&, A>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary,
int&, int[]>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary,
const int&, int[]>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary,
int&&, int[]>(false), "");
+
+ static_assert(test_property<reference_converts_from_temporary, int,
int>(false), "");
+ static_assert(test_property<reference_converts_from_temporary,
int&, void>(false), "");
+ static_assert(test_property<reference_converts_from_temporary,
int&, const volatile void>(false), "");
+ static_assert(test_property<reference_converts_from_temporary,
void, void>(false), "");
+ static_assert(test_property<reference_converts_from_temporary,
int&, int>(false), "");
+ static_assert(test_property<reference_converts_from_temporary,
int&, int&>(false), "");
+ static_assert(test_property<reference_converts_from_temporary,
int&, int&&>(false), "");
+ static_assert(test_property<reference_converts_from_temporary,
int&, long>(false), "");
+ static_assert(test_property<reference_converts_from_temporary,
int&, long&>(false), "");
+ static_assert(test_property<reference_converts_from_temporary,
int&, long&&>(false), "");
+ static_assert(test_property<reference_converts_from_temporary,
const int&, int>(true), "");
+ static_assert(test_property<reference_converts_from_temporary,
const int&, int&>(false), "");
+ static_assert(test_property<reference_converts_from_temporary,
const int&, int&&>(false), "");
+ static_assert(test_property<reference_converts_from_temporary,
const int&, long>(true), "");
+ static_assert(test_property<reference_converts_from_temporary,
const int&, long&>(true), "");
+ static_assert(test_property<reference_converts_from_temporary,
const int&, long&&>(true), "");
+ static_assert(test_property<reference_converts_from_temporary,
int&&, int>(true), "");
+ static_assert(test_property<reference_converts_from_temporary,
int&&, int&>(false), "");
+ static_assert(test_property<reference_converts_from_temporary,
int&&, int&&>(false), "");
+ static_assert(test_property<reference_converts_from_temporary,
int&&, long>(true), "");
+ static_assert(test_property<reference_converts_from_temporary,
int&&, long&>(true), "");
+ static_assert(test_property<reference_converts_from_temporary,
int&&, long&&>(true), "");
+ static_assert(test_property<reference_converts_from_temporary,
const A&, A>(true), "");
+ static_assert(test_property<reference_converts_from_temporary,
const A&, A&&>(false), "");
+ static_assert(test_property<reference_converts_from_temporary, A&&,
A>(true), "");
+ static_assert(test_property<reference_converts_from_temporary,
int&, int[]>(false), "");
+ static_assert(test_property<reference_converts_from_temporary,
const int&, int[]>(false), "");
+ static_assert(test_property<reference_converts_from_temporary,
int&&, int[]>(false), "");
+
+ static_assert(test_property<reference_constructs_from_temporary,
int&&, B>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary,
const int&, C>(false), "");
+ static_assert(test_property<reference_converts_from_temporary,
int&&, B>(true), "");
+ static_assert(test_property<reference_converts_from_temporary,
const int&, C>(true), "");
+}
diff --git
a/libstdc++-v3/testsuite/20_util/reference_from_temporary/value2.cc
b/libstdc++-v3/testsuite/20_util/reference_from_temporary/value2.cc
new file mode 100644
index 00000000000..65770754299
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/reference_from_temporary/value2.cc
@@ -0,0 +1,28 @@
+// Copyright (C) 2022 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++23" }
+// { dg-do compile { target c++23 } }
+
+#include <type_traits>
+#include <string>
+
+void test01()
+{
+ static_assert(std::reference_converts_from_temporary_v<const
std::string&, const char*>);
+ static_assert(std::reference_constructs_from_temporary_v<const
std::string&, const char*>);
+}
diff --git
a/libstdc++-v3/testsuite/20_util/reference_from_temporary/version.cc
b/libstdc++-v3/testsuite/20_util/reference_from_temporary/version.cc
new file mode 100644
index 00000000000..f56e7c0dabc
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/reference_from_temporary/version.cc
@@ -0,0 +1,27 @@
+// Copyright (C) 2022 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++23" }
+// { dg-do compile { target c++23 } }
+
+#include <version>
+
+#ifndef __cpp_lib_reference_from_temporary
+# error "Feature test macro for reference_from_temporary is missing
in <version>"
+#elif __cpp_lib_reference_from_temporary < 202202L
+# error "Feature test macro for reference_from_temporary has wrong
value in <version>"
+#endif
diff --git
a/libstdc++-v3/testsuite/20_util/variable_templates_for_traits.cc
b/libstdc++-v3/testsuite/20_util/variable_templates_for_traits.cc
index 9b3957f7d47..2b03ad7067d 100644
--- a/libstdc++-v3/testsuite/20_util/variable_templates_for_traits.cc
+++ b/libstdc++-v3/testsuite/20_util/variable_templates_for_traits.cc
@@ -346,3 +346,17 @@ static_assert(disjunction_v<false_type, false_type,
true_type>, "");
static_assert(!disjunction_v<false_type, false_type,
false_type>, "");
+#if __cpp_lib_reference_from_temporary >= 202202L
+static_assert(std::reference_converts_from_temporary_v<int&&, int>
+ && std::reference_converts_from_temporary_v<const int&, int>
+ && !std::reference_converts_from_temporary_v<int&&, int&&>
+ && !std::reference_converts_from_temporary_v<const int&,
int&&>
+ && std::reference_converts_from_temporary_v<int&&, long&&>
+ && std::reference_converts_from_temporary_v<int&&, long>, "");
+static_assert(std::reference_constructs_from_temporary_v<int&&, int>
+ && std::reference_constructs_from_temporary_v<const int&, int>
+ && !std::reference_constructs_from_temporary_v<int&&, int&&>
+ && !std::reference_constructs_from_temporary_v<const int&,
int&&>
+ && std::reference_constructs_from_temporary_v<int&&, long&&>
+ && std::reference_constructs_from_temporary_v<int&&, long>,
"");
+#endif
base-commit: 55bb77b50a5ec520f28978ac3fdac1983200e1f7