// -*- C++ -*- //===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03 // // template tuple(TupleLike&&); // libc++ extension // See llvm.org/PR31384 #include #include 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() { { 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; }