| 1 | // { dg-do compile { target c++11 } } |
| 2 | // { dg-options "-Wno-unused-variable" } |
| 3 | // { dg-additional-options "-D_GLIBCXX_DEBUG" { target c++17_down } } |
| 4 | // { dg-skip-if "cannot mix with DEBUG" { *-*-* } { "-D_GLIBCXX_PARALLEL" } } |
| 5 | #include <utility> |
| 6 | |
| 7 | #if __cplusplus >= 202002L |
| 8 | // For C++20 and later, constructors are constrained to disallow dangling. |
| 9 | static_assert(!std::is_constructible_v<std::pair<const int&, int>, long, int>); |
| 10 | static_assert(!std::is_constructible_v<std::pair<int, const int&>, int, long>); |
| 11 | static_assert(!std::is_constructible_v<std::pair<const int&, int>, |
| 12 | std::pair<long, long>>); |
| 13 | static_assert(!std::is_constructible_v<std::pair<int, const int&>, |
| 14 | std::pair<long, long>>); |
| 15 | static_assert(!std::is_constructible_v<std::pair<const int&, int>, |
| 16 | const std::pair<long, long>&>); |
| 17 | static_assert(!std::is_constructible_v<std::pair<int, const int&>, |
| 18 | const std::pair<long, long>&>); |
| 19 | #endif |
| 20 | |
| 21 | void |
| 22 | test_binary_ctors() |
| 23 | { |
| 24 | std::pair<const int&, int> p1(1L, 2); |
| 25 | // { dg-error "here" "" { target { c++17_down && hosted } } 24 } |
| 26 | // { dg-error "use of deleted function" "" { target c++20 } 24 } |
| 27 | |
| 28 | std::pair<int, const int&> p2(1, 2L); |
| 29 | // { dg-error "here" "" { target { c++17_down && hosted } } 28 } |
| 30 | // { dg-error "use of deleted function" "" { target c++20 } 28 } |
| 31 | |
| 32 | std::pair<const int&, const int&> p3(1L, 2L); |
| 33 | // { dg-error "here" "" { target { c++17_down && hosted } } 32 } |
| 34 | // { dg-error "use of deleted function" "" { target c++20 } 32 } |
| 35 | } |
| 36 | |
| 37 | void |
| 38 | test_converting_ctors() |
| 39 | { |
| 40 | std::pair<long, long> p0; |
| 41 | |
| 42 | std::pair<const int&, int> p1(p0); |
| 43 | // { dg-error "here" "" { target { c++17_down && hosted } } 42 } |
| 44 | // { dg-error "use of deleted function" "" { target c++20 } 42 } |
| 45 | |
| 46 | std::pair<int, const int&> p2(p0); |
| 47 | // { dg-error "here" "" { target { c++17_down && hosted } } 46 } |
| 48 | // { dg-error "use of deleted function" "" { target c++20 } 46 } |
| 49 | |
| 50 | std::pair<const int&, const int&> p3(p0); |
| 51 | // { dg-error "here" "" { target { c++17_down && hosted } } 50 } |
| 52 | // { dg-error "use of deleted function" "" { target c++20 } 50 } |
| 53 | |
| 54 | std::pair<const int&, int> p4(std::move(p0)); |
| 55 | // { dg-error "here" "" { target { c++17_down && hosted } } 54 } |
| 56 | // { dg-error "use of deleted function" "" { target c++20 } 54 } |
| 57 | |
| 58 | std::pair<int, const int&> p5(std::move(p0)); |
| 59 | // { dg-error "here" "" { target { c++17_down && hosted } } 58 } |
| 60 | // { dg-error "use of deleted function" "" { target c++20 } 58 } |
| 61 | |
| 62 | std::pair<const int&, const int&> p6(std::move(p0)); |
| 63 | // { dg-error "here" "" { target { c++17_down && hosted } } 62 } |
| 64 | // { dg-error "use of deleted function" "" { target c++20 } 62 } |
| 65 | } |
| 66 | |
| 67 | // { dg-error "static assert.* dangling reference" "" { target { c++17_down && hosted } } 0 } |