// -*- C++ -*- //===----------------------------------------------------------------------===// // // 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++98, c++03 // // template tuple(TupleLike&&); // libc++ extension // See 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); std::tuple bar(Derived{42}); ((void)bar); assert(count == 2); } count = 0; { std::tuple foo = Derived{42}; ((void)foo); assert(count == 1); std::tuple bar(Derived{42}); ((void)bar); assert(count == 2); } count = 0; { static_assert(!std::is_convertible< ExplicitDerived, std::tuple>::value, ""); std::tuple bar(ExplicitDerived{42}); ((void)bar); assert(count == 1); } count = 0; { // FIXME: Libc++ incorrectly rejects this code. #ifndef _LIBCPP_VERSION std::tuple foo = ExplicitDerived{42}; ((void)foo); static_assert(std::is_convertible< ExplicitDerived, std::tuple>::value, "correct STLs accept this"); #else static_assert(!std::is_convertible< ExplicitDerived, std::tuple>::value, "libc++ incorrectly rejects this"); #endif assert(count == 0); std::tuple bar(ExplicitDerived{42}); ((void)bar); assert(count == 1); } count = 0; return 0; }