[libcxx] r271489 - Mark LWG issue 2545 as complete. Add extra tests

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 1 22:44:15 PDT 2016


Author: ericwf
Date: Thu Jun  2 00:44:14 2016
New Revision: 271489

URL: http://llvm.org/viewvc/llvm-project?rev=271489&view=rev
Log:
Mark LWG issue 2545 as complete. Add extra tests

Added:
    libcxx/trunk/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/bind_return_type.pass.cpp
Modified:
    libcxx/trunk/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp
    libcxx/trunk/www/cxx1z_status.html

Added: libcxx/trunk/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/bind_return_type.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/bind_return_type.pass.cpp?rev=271489&view=auto
==============================================================================
--- libcxx/trunk/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/bind_return_type.pass.cpp (added)
+++ libcxx/trunk/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/bind_return_type.pass.cpp Thu Jun  2 00:44:14 2016
@@ -0,0 +1,131 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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
+
+// <functional>
+
+// template<CopyConstructible Fn, CopyConstructible... Types>
+//   unspecified bind(Fn, Types...);
+// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
+//   unspecified bind(Fn, Types...);
+
+// Check that the call operators have the proper return type and that they
+// only SFINAE away when too few arguments are provided. Otherwise they should
+// be well formed and should ignore any additional arguments.
+
+#include <functional>
+#include <type_traits>
+#include <cassert>
+
+int dummy = 42;
+
+int return_value(int) { return dummy; }
+int& return_lvalue(int) { return dummy; }
+const int& return_const_lvalue(int) { return dummy; }
+int&& return_rvalue(int) { return std::move(dummy); }
+const int&& return_const_rvalue(int) { return std::move(dummy); }
+
+template <class Bind, class ...Args>
+auto CheckCallImp(int)
+    -> decltype((std::declval<Bind>()(std::declval<Args>()...)), std::true_type{});
+
+template <class Bind, class ...>
+auto CheckCallImp(long) -> std::false_type;
+
+template <class ...Args>
+constexpr bool CheckCall() {
+    return decltype(CheckCallImp<Args...>(0))::value;
+}
+
+template <class Expect, class Fn>
+void do_test(Fn* func) {
+    using namespace std::placeholders;
+    auto ret = std::bind(func, _1);
+    auto ret_r = std::bind<Expect>(func, _1);
+    using Bind = decltype(ret);
+    using BindR = decltype(ret_r);
+
+    using Ret = decltype(ret(42));
+    using Ret2 = decltype(ret(42, 43)); // Test that the extra argument is discarded.
+    using RetR = decltype(ret_r(42));
+    using RetR2 = decltype(ret_r(42, 43));
+
+    static_assert(std::is_same<Ret, Expect>::value, "");
+    static_assert(std::is_same<Ret2, Expect>::value, "");
+    static_assert(std::is_same<RetR, Expect>::value, "");
+    static_assert(std::is_same<RetR2, Expect>::value, "");
+
+    Expect exp = ret(100); // the input value is ignored. dummy is returned.
+    Expect exp2 = ret(101, 102);
+    Expect exp_r = ret_r(100);
+    Expect exp_r2 = ret_r(101, 102);
+
+    assert(exp == 42);
+    assert(exp2 == 42);
+    assert(exp_r == 42);
+    assert(exp_r2 == 42);
+
+    if ((std::is_reference<Expect>::value)) {
+        assert(&exp == &dummy);
+        assert(&exp2 == &dummy);
+        assert(&exp_r == &dummy);
+        assert(&exp_r2 == &dummy);
+    }
+    // Check that the call operator SFINAE's away when too few arguments
+    // are provided but is well-formed otherwise.
+    {
+        static_assert(!CheckCall<Bind>(), "");
+        static_assert(CheckCall<Bind, int>(), "");
+        static_assert(CheckCall<Bind, int, int>(), "");
+        static_assert(!CheckCall<BindR>(), "");
+        static_assert(CheckCall<BindR, int>(), "");
+        static_assert(CheckCall<BindR, int, int>(), "");
+    }
+}
+
+
+// Test but with an explicit return type which differs from the real one.
+template <class Expect, class Fn>
+void do_test_r(Fn* func) {
+    using namespace std::placeholders;
+    auto ret = std::bind<Expect>(func, _1);
+    using Bind = decltype(ret);
+    using Ret = decltype(ret(42));
+    using Ret2 = decltype(ret(42, 43)); // Test that the extra argument is discarded.
+    static_assert(std::is_same<Ret, Expect>::value, "");
+    static_assert(std::is_same<Ret2, Expect>::value, "");
+    Expect exp = ret(100); // the input value is ignored
+    Expect exp2 = ret(101, 102);
+    assert(exp == 42);
+    assert(exp2 == 42);
+    // Check that the call operator SFINAE's away when too few arguments
+    // are provided but is well-formed otherwise.
+    {
+        static_assert(!CheckCall<Bind>(), "");
+        static_assert(CheckCall<Bind, int>(), "");
+        static_assert(CheckCall<Bind, int, int>(), "");
+    }
+}
+
+int main()
+{
+    do_test<int>(return_value);
+    do_test<int&>(return_lvalue);
+    do_test<const int&>(return_const_lvalue);
+    do_test<int&&>(return_rvalue);
+    do_test<const int&&>(return_const_rvalue);
+
+    do_test_r<long>(return_value);
+    do_test_r<long>(return_lvalue);
+    do_test_r<long>(return_const_lvalue);
+    do_test_r<long>(return_rvalue);
+    do_test_r<long>(return_const_rvalue);
+
+}

Modified: libcxx/trunk/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp?rev=271489&r1=271488&r2=271489&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_lvalue.pass.cpp Thu Jun  2 00:44:14 2016
@@ -286,4 +286,5 @@ int main()
     test_void_1();
     test_int_1();
     test_void_2();
+    test3();
 }

Modified: libcxx/trunk/www/cxx1z_status.html
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1z_status.html?rev=271489&r1=271488&r2=271489&view=diff
==============================================================================
--- libcxx/trunk/www/cxx1z_status.html (original)
+++ libcxx/trunk/www/cxx1z_status.html Thu Jun  2 00:44:14 2016
@@ -211,7 +211,7 @@
 	<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2523">2523</a></td><td><tt>std::promise</tt> synopsis shows two <tt>set_value_at_thread_exit()</tt>'s for no apparent reason</td><td>Jacksonville</td><td>Complete</td></tr>
 	<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2537">2537</a></td><td>Constructors for <code>priority_queue</code> taking allocators should call <code>make_heap</code></td><td>Jacksonville</td><td>Complete</td></tr>
 	<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2539">2539</a></td><td>[fund.ts.v2] <tt>invocation_trait</tt> definition definition doesn't work for surrogate call functions</td><td>Jacksonville</td><td></td></tr>
-	<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2545">2545</a></td><td>Simplify wording for <tt>bind</tt> without explicitly specified return type</td><td>Jacksonville</td><td></td></tr>
+	<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2545">2545</a></td><td>Simplify wording for <tt>bind</tt> without explicitly specified return type</td><td>Jacksonville</td><td>Complete</td></tr>
 	<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2557">2557</a></td><td>Logical operator traits are broken in the zero-argument case</td><td>Jacksonville</td><td>Complete</td></tr>
 	<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2558">2558</a></td><td>[fund.ts.v2] Logical operator traits are broken in the zero-argument case</td><td>Jacksonville</td><td>Complete</td></tr>
 	<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2559">2559</a></td><td>Error in LWG 2234's resolution</td><td>Jacksonville</td><td>Complete</td></tr>




More information about the cfe-commits mailing list