// { dg-do compile { target c++11 } } // { dg-options "-Wno-unused-variable" } // { dg-additional-options "-D_GLIBCXX_DEBUG" { target c++17_down } } // { dg-skip-if "cannot mix with DEBUG" { *-*-* } { "-D_GLIBCXX_PARALLEL" } } #include #if __cplusplus >= 202002L // For C++20 and later, constructors are constrained to disallow dangling. static_assert(!std::is_constructible_v, long, int>); static_assert(!std::is_constructible_v, int, long>); static_assert(!std::is_constructible_v, std::pair>); static_assert(!std::is_constructible_v, std::pair>); static_assert(!std::is_constructible_v, const std::pair&>); static_assert(!std::is_constructible_v, const std::pair&>); #endif void test_binary_ctors() { std::pair p1(1L, 2); // { dg-error "here" "" { target { c++17_down && hosted } } 24 } // { dg-error "use of deleted function" "" { target c++20 } 24 } std::pair p2(1, 2L); // { dg-error "here" "" { target { c++17_down && hosted } } 28 } // { dg-error "use of deleted function" "" { target c++20 } 28 } std::pair p3(1L, 2L); // { dg-error "here" "" { target { c++17_down && hosted } } 32 } // { dg-error "use of deleted function" "" { target c++20 } 32 } } void test_converting_ctors() { std::pair p0; std::pair p1(p0); // { dg-error "here" "" { target { c++17_down && hosted } } 42 } // { dg-error "use of deleted function" "" { target c++20 } 42 } std::pair p2(p0); // { dg-error "here" "" { target { c++17_down && hosted } } 46 } // { dg-error "use of deleted function" "" { target c++20 } 46 } std::pair p3(p0); // { dg-error "here" "" { target { c++17_down && hosted } } 50 } // { dg-error "use of deleted function" "" { target c++20 } 50 } std::pair p4(std::move(p0)); // { dg-error "here" "" { target { c++17_down && hosted } } 54 } // { dg-error "use of deleted function" "" { target c++20 } 54 } std::pair p5(std::move(p0)); // { dg-error "here" "" { target { c++17_down && hosted } } 58 } // { dg-error "use of deleted function" "" { target c++20 } 58 } std::pair p6(std::move(p0)); // { dg-error "here" "" { target { c++17_down && hosted } } 62 } // { dg-error "use of deleted function" "" { target c++20 } 62 } } // { dg-error "static assert.* dangling reference" "" { target { c++17_down && hosted } } 0 }