| 1 |
// Copyright (C) 2022-2025 Free Software Foundation, Inc. |
| 2 |
// |
| 3 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 4 |
// software; you can redistribute it and/or modify it under the |
| 5 |
// terms of the GNU General Public License as published by the |
| 6 |
// Free Software Foundation; either version 3, or (at your option) |
| 7 |
// any later version. |
| 8 |
|
| 9 |
// This library is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU General Public License for more details. |
| 13 |
|
| 14 |
// You should have received a copy of the GNU General Public License along |
| 15 |
// with this library; see the file COPYING3. If not see |
| 16 |
// <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
// { dg-do compile { target c++23 } } |
| 19 |
// { dg-add-options no_pch } |
| 20 |
|
| 21 |
#include <type_traits> |
| 22 |
|
| 23 |
#ifndef __cpp_lib_reference_from_temporary |
| 24 |
# error "Feature test macro for reference_from_temporary is missing in <type_traits>" |
| 25 |
#elif __cpp_lib_reference_from_temporary < 202202L |
| 26 |
# error "Feature test macro for reference_from_temporary has wrong value in <type_traits>" |
| 27 |
#endif |
| 28 |
|
| 29 |
#include <testsuite_tr1.h> |
| 30 |
|
| 31 |
void test01() |
| 32 |
{ |
| 33 |
using std::reference_constructs_from_temporary; |
| 34 |
using std::reference_converts_from_temporary; |
| 35 |
using namespace __gnu_test; |
| 36 |
|
| 37 |
struct A { A(); }; |
| 38 |
|
| 39 |
struct B { |
| 40 |
operator int(); |
| 41 |
explicit operator int&&(); |
| 42 |
}; |
| 43 |
|
| 44 |
struct C { |
| 45 |
operator int(); |
| 46 |
explicit operator int&(); |
| 47 |
}; |
| 48 |
|
| 49 |
static_assert(test_property<reference_constructs_from_temporary, int, int>(false), ""); |
| 50 |
static_assert(test_property<reference_constructs_from_temporary, int&, void>(false), ""); |
| 51 |
static_assert(test_property<reference_constructs_from_temporary, int&, const volatile void>(false), ""); |
| 52 |
static_assert(test_property<reference_constructs_from_temporary, void, void>(false), ""); |
| 53 |
static_assert(test_property<reference_constructs_from_temporary, int&, int>(false), ""); |
| 54 |
static_assert(test_property<reference_constructs_from_temporary, int&, int&>(false), ""); |
| 55 |
static_assert(test_property<reference_constructs_from_temporary, int&, int&&>(false), ""); |
| 56 |
static_assert(test_property<reference_constructs_from_temporary, int&, long>(false), ""); |
| 57 |
static_assert(test_property<reference_constructs_from_temporary, int&, long&>(false), ""); |
| 58 |
static_assert(test_property<reference_constructs_from_temporary, int&, long&&>(false), ""); |
| 59 |
static_assert(test_property<reference_constructs_from_temporary, const int&, int>(true), ""); |
| 60 |
static_assert(test_property<reference_constructs_from_temporary, const int&, int&>(false), ""); |
| 61 |
static_assert(test_property<reference_constructs_from_temporary, const int&, int&&>(false), ""); |
| 62 |
static_assert(test_property<reference_constructs_from_temporary, const int&, long>(true), ""); |
| 63 |
static_assert(test_property<reference_constructs_from_temporary, const int&, long&>(true), ""); |
| 64 |
static_assert(test_property<reference_constructs_from_temporary, const int&, long&&>(true), ""); |
| 65 |
static_assert(test_property<reference_constructs_from_temporary, int&&, int>(true), ""); |
| 66 |
static_assert(test_property<reference_constructs_from_temporary, int&&, int&>(false), ""); |
| 67 |
static_assert(test_property<reference_constructs_from_temporary, int&&, int&&>(false), ""); |
| 68 |
static_assert(test_property<reference_constructs_from_temporary, int&&, long>(true), ""); |
| 69 |
static_assert(test_property<reference_constructs_from_temporary, int&&, long&>(true), ""); |
| 70 |
static_assert(test_property<reference_constructs_from_temporary, int&&, long&&>(true), ""); |
| 71 |
static_assert(test_property<reference_constructs_from_temporary, const A&, A>(true), ""); |
| 72 |
static_assert(test_property<reference_constructs_from_temporary, const A&, A&&>(false), ""); |
| 73 |
static_assert(test_property<reference_constructs_from_temporary, A&&, A>(true), ""); |
| 74 |
static_assert(test_property<reference_constructs_from_temporary, int&, int[]>(false), ""); |
| 75 |
static_assert(test_property<reference_constructs_from_temporary, const int&, int[]>(false), ""); |
| 76 |
static_assert(test_property<reference_constructs_from_temporary, int&&, int[]>(false), ""); |
| 77 |
|
| 78 |
static_assert(test_property<reference_converts_from_temporary, int, int>(false), ""); |
| 79 |
static_assert(test_property<reference_converts_from_temporary, int&, void>(false), ""); |
| 80 |
static_assert(test_property<reference_converts_from_temporary, int&, const volatile void>(false), ""); |
| 81 |
static_assert(test_property<reference_converts_from_temporary, void, void>(false), ""); |
| 82 |
static_assert(test_property<reference_converts_from_temporary, int&, int>(false), ""); |
| 83 |
static_assert(test_property<reference_converts_from_temporary, int&, int&>(false), ""); |
| 84 |
static_assert(test_property<reference_converts_from_temporary, int&, int&&>(false), ""); |
| 85 |
static_assert(test_property<reference_converts_from_temporary, int&, long>(false), ""); |
| 86 |
static_assert(test_property<reference_converts_from_temporary, int&, long&>(false), ""); |
| 87 |
static_assert(test_property<reference_converts_from_temporary, int&, long&&>(false), ""); |
| 88 |
static_assert(test_property<reference_converts_from_temporary, const int&, int>(true), ""); |
| 89 |
static_assert(test_property<reference_converts_from_temporary, const int&, int&>(false), ""); |
| 90 |
static_assert(test_property<reference_converts_from_temporary, const int&, int&&>(false), ""); |
| 91 |
static_assert(test_property<reference_converts_from_temporary, const int&, long>(true), ""); |
| 92 |
static_assert(test_property<reference_converts_from_temporary, const int&, long&>(true), ""); |
| 93 |
static_assert(test_property<reference_converts_from_temporary, const int&, long&&>(true), ""); |
| 94 |
static_assert(test_property<reference_converts_from_temporary, int&&, int>(true), ""); |
| 95 |
static_assert(test_property<reference_converts_from_temporary, int&&, int&>(false), ""); |
| 96 |
static_assert(test_property<reference_converts_from_temporary, int&&, int&&>(false), ""); |
| 97 |
static_assert(test_property<reference_converts_from_temporary, int&&, long>(true), ""); |
| 98 |
static_assert(test_property<reference_converts_from_temporary, int&&, long&>(true), ""); |
| 99 |
static_assert(test_property<reference_converts_from_temporary, int&&, long&&>(true), ""); |
| 100 |
static_assert(test_property<reference_converts_from_temporary, const A&, A>(true), ""); |
| 101 |
static_assert(test_property<reference_converts_from_temporary, const A&, A&&>(false), ""); |
| 102 |
static_assert(test_property<reference_converts_from_temporary, A&&, A>(true), ""); |
| 103 |
static_assert(test_property<reference_converts_from_temporary, int&, int[]>(false), ""); |
| 104 |
static_assert(test_property<reference_converts_from_temporary, const int&, int[]>(false), ""); |
| 105 |
static_assert(test_property<reference_converts_from_temporary, int&&, int[]>(false), ""); |
| 106 |
|
| 107 |
static_assert(test_property<reference_constructs_from_temporary, int&&, B>(false), ""); |
| 108 |
static_assert(test_property<reference_constructs_from_temporary, const int&, C>(false), ""); |
| 109 |
static_assert(test_property<reference_converts_from_temporary, int&&, B>(true), ""); |
| 110 |
static_assert(test_property<reference_converts_from_temporary, const int&, C>(true), ""); |
| 111 |
} |