//===----------------------------------------------------------------------===// // // 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 // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03 // FIXME: Why does this start to fail with GCC 14? // XFAIL: !(c++11 || c++14) && gcc-14 // See https://llvm.org/PR31384. #include #include #include "test_macros.h" int count = 0; struct Explicit { Explicit() = default; explicit Explicit(int) {} }; struct Implicit { Implicit() = default; Implicit(int) {} }; template struct Derived : std::tuple { using std::tuple::tuple; template operator std::tuple() && { ++count; return {}; } }; template struct ExplicitDerived : std::tuple { using std::tuple::tuple; template explicit operator std::tuple() && { ++count; return {}; } }; int main(int, char**) { { std::tuple foo = Derived{42}; ((void)foo); assert(count == 1); Derived d{42}; std::tuple bar(std::move(d)); ((void)bar); #if TEST_STD_VER < 17 assert(count == 1); #else assert(count == 2); #endif } count = 0; { std::tuple foo = Derived{42}; ((void)foo); assert(count == 1); Derived d{42}; std::tuple bar(std::move(d)); ((void)bar); #if TEST_STD_VER < 17 assert(count == 1); #else assert(count == 2); #endif } count = 0; { static_assert(!std::is_convertible, std::tuple>::value, ""); ExplicitDerived d{42}; std::tuple bar(std::move(d)); ((void)bar); #if TEST_STD_VER < 17 assert(count == 0); #else assert(count == 1); #endif } count = 0; { std::tuple foo = ExplicitDerived{42}; ((void)foo); static_assert(std::is_convertible, std::tuple>::value, ""); assert(count == 0); ExplicitDerived d{42}; std::tuple bar(std::move(d)); ((void)bar); #if TEST_STD_VER < 17 assert(count == 0); #else assert(count == 1); #endif } count = 0; return 0; }