From 90314c55d1df9e2983f35d2f3ca065a76d1236e1 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Thu, 15 Dec 2016 07:05:19 +0000 Subject: [PATCH] Add more test cases for PR31384 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@289778 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../tuple.tuple/tuple.cnstr/PR31384.pass.cpp | 68 ++++++++++++++++--- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR31384.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR31384.pass.cpp index 9fde7ac9a..30e020e8f 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR31384.pass.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR31384.pass.cpp @@ -15,24 +15,74 @@ // 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 { +struct Derived : std::tuple { using std::tuple::tuple; template - operator std::tuple() && { - ++count; - return {}; - } + 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}; - assert(count == 1); + { + std::tuple foo = Derived{42}; + assert(count == 1); + std::tuple bar(Derived{42}); + assert(count == 2); + } + count = 0; + { + std::tuple foo = Derived{42}; + assert(count == 1); + std::tuple bar(Derived{42}); + assert(count == 2); + } + count = 0; + { + static_assert(!std::is_convertible< + ExplicitDerived, std::tuple>::value, ""); + std::tuple bar(ExplicitDerived{42}); + assert(count == 1); + } + count = 0; + { + // FIXME: Libc++ incorrectly rejects this code. +#ifndef _LIBCPP_VERSION + std::tuple foo = ExplicitDerived{42}; + 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}); + assert(count == 1); + } + count = 0; + }