From 2152fd7682e3725449fc6483141dc55fc80dad16 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Mon, 18 Apr 2016 06:17:30 +0000 Subject: Implement LWG issue 2219 - support reference_wrapper in INVOKE llvm-svn: 266590 --- .../func.require/bullet_1_2_3.pass.cpp | 367 +++++++++++++++++++++ .../func.require/bullet_1_and_2.pass.cpp | 318 ------------------ .../func.require/bullet_3_and_4.pass.cpp | 164 --------- .../func.require/bullet_4_5_6.pass.cpp | 205 ++++++++++++ .../func.require/bullet_5.pass.cpp | 327 ------------------ .../func.require/bullet_7.pass.cpp | 327 ++++++++++++++++++ .../function.objects/func.require/invoke_helpers.h | 34 ++ 7 files changed, 933 insertions(+), 809 deletions(-) create mode 100644 libcxx/test/std/utilities/function.objects/func.require/bullet_1_2_3.pass.cpp delete mode 100644 libcxx/test/std/utilities/function.objects/func.require/bullet_1_and_2.pass.cpp delete mode 100644 libcxx/test/std/utilities/function.objects/func.require/bullet_3_and_4.pass.cpp create mode 100644 libcxx/test/std/utilities/function.objects/func.require/bullet_4_5_6.pass.cpp delete mode 100644 libcxx/test/std/utilities/function.objects/func.require/bullet_5.pass.cpp create mode 100644 libcxx/test/std/utilities/function.objects/func.require/bullet_7.pass.cpp (limited to 'libcxx/test/std/utilities/function.objects/func.require') diff --git a/libcxx/test/std/utilities/function.objects/func.require/bullet_1_2_3.pass.cpp b/libcxx/test/std/utilities/function.objects/func.require/bullet_1_2_3.pass.cpp new file mode 100644 index 00000000000..09e8e21137a --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/func.require/bullet_1_2_3.pass.cpp @@ -0,0 +1,367 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// INVOKE (f, t1, t2, ..., tN) + +//------------------------------------------------------------------------------ +// TESTING INVOKE(f, t1, t2, ..., tN) +// - Bullet 1 -- (t1.*f)(t2, ..., tN) +// - Bullet 2 -- (t1.get().*f)(t2, ..., tN) // t1 is a reference_wrapper +// - Bullet 3 -- ((*t1).*f)(t2, ..., tN) +// +// Overview: +// Bullets 1, 2 and 3 handle the case where 'f' is a pointer to member function. +// Bullet 1 only handles the cases where t1 is an object of type T or a +// type derived from 'T'. Bullet 2 handles the case where 't1' is a reference +// wrapper and bullet 3 handles all other cases. +// +// Concerns: +// 1) cv-qualified member function signatures are accepted. +// 2) reference qualified member function signatures are accepted. +// 3) member functions with varargs at the end are accepted. +// 4) The arguments are perfect forwarded to the member function call. +// 5) Classes that are publicly derived from 'T' are accepted as the call object +// 6) All types that dereference to T or a type derived from T can be used +// as the call object. +// 7) Pointers to T or a type derived from T can be used as the call object. +// 8) Reference return types are properly deduced. +// 9) reference_wrappers are properly handled and unwrapped. +// +// +// Plan: +// 1) Create a class that contains a set, 'S', of non-static functions. +// 'S' should include functions that cover every single combination +// of qualifiers and varargs for arities of 0, 1 and 2 (C-1,2,3). +// The argument types used in the functions should be non-copyable (C-4). +// The functions should return 'MethodID::setUncheckedCall()'. +// +// 2) Create a set of supported call object, 'Objs', of different types +// and behaviors. (C-5,6,7) +// +// 3) Attempt to call each function, 'f', in 'S' with each call object, 'c', +// in 'Objs'. After every attempted call to 'f' check that 'f' was +// actually called using 'MethodID::checkCalled()' +// +// 3b) If 'f' is reference qualified call 'f' with the properly qualified +// call object. Otherwise call 'f' with lvalue call objects. +// +// 3a) If 'f' is const, volatile, or cv qualified then call it with call +// objects that are equally or less cv-qualified. + +#include +#include +#include + +#include "test_macros.h" +#include "invoke_helpers.h" + +//============================================================================== +// MemFun03 - C++03 compatible set of test member functions. +struct MemFun03 { + typedef void*& R; +#define F(...) \ + R f(__VA_ARGS__) { return MethodID::setUncheckedCall(); } \ + R f(__VA_ARGS__) const { return MethodID::setUncheckedCall(); } \ + R f(__VA_ARGS__) volatile { return MethodID::setUncheckedCall(); } \ + R f(__VA_ARGS__) const volatile { return MethodID::setUncheckedCall(); } +# + F() + F(...) + F(ArgType&) + F(ArgType&, ...) + F(ArgType&, ArgType&) + F(ArgType&, ArgType&, ...) + F(ArgType&, ArgType&, ArgType&) + F(ArgType&, ArgType&, ArgType&, ...) +#undef F +public: + MemFun03() {} +private: + MemFun03(MemFun03 const&); + MemFun03& operator=(MemFun03 const&); +}; + + +#if TEST_STD_VER >= 11 + +//============================================================================== +// MemFun11 - C++11 reference qualified test member functions. +struct MemFun11 { + typedef void*& R; + typedef MemFun11 C; +#define F(...) \ + R f(__VA_ARGS__) & { return MethodID::setUncheckedCall(); } \ + R f(__VA_ARGS__) const & { return MethodID::setUncheckedCall(); } \ + R f(__VA_ARGS__) volatile & { return MethodID::setUncheckedCall(); } \ + R f(__VA_ARGS__) const volatile & { return MethodID::setUncheckedCall(); } \ + R f(__VA_ARGS__) && { return MethodID::setUncheckedCall(); } \ + R f(__VA_ARGS__) const && { return MethodID::setUncheckedCall(); } \ + R f(__VA_ARGS__) volatile && { return MethodID::setUncheckedCall(); } \ + R f(__VA_ARGS__) const volatile && { return MethodID::setUncheckedCall(); } +# + F() + F(...) + F(ArgType&&) + F(ArgType&&, ...) + F(ArgType&&, ArgType&&) + F(ArgType&&, ArgType&&, ...) + F(ArgType&&, ArgType&&, ArgType&&) + F(ArgType&&, ArgType&&, ArgType&&, ...) +#undef F +public: + MemFun11() {} +private: + MemFun11(MemFun11 const&); + MemFun11& operator=(MemFun11 const&); +}; + +#endif // TEST_STD_VER >= 11 + + + +//============================================================================== +// TestCase - A test case for a single member function. +// ClassType - The type of the class being tested. +// CallSig - The function signature of the method being tested. +// Arity - the arity of 'CallSig' +// CV - the cv qualifiers of 'CallSig' represented as a type tag. +// RValue - The method is RValue qualified. +// ArgRValue - Call the method with RValue arguments. +template +struct TestCaseImp { +public: + + static void run() { TestCaseImp().doTest(); } + +private: + //========================================================================== + // TEST DISPATCH + void doTest() { + // (Plan-2) Create test call objects. + typedef ClassType T; + typedef DerivedFromType D; + T obj; + T* obj_ptr = &obj; + D der; + D* der_ptr = &der; + DerefToType dref; + DerefPropType dref2; + std::reference_wrapper rref(obj); + std::reference_wrapper drref(der); + + // (Plan-3) Dispatch based on the CV tags. + CV tag; + Bool NotRValue; + runTestDispatch(tag, obj); + runTestDispatch(tag, der); + runTestDispatch(tag, dref2); + runTestDispatchIf(NotRValue, tag, dref); + runTestDispatchIf(NotRValue, tag, obj_ptr); + runTestDispatchIf(NotRValue, tag, der_ptr); +#if TEST_STD_VER >= 11 + runTestDispatchIf(NotRValue, tag, rref); + runTestDispatchIf(NotRValue, tag, drref); +#endif + } + + template + void runTestDispatchIf(Bool, QT q, Tp& v) { + runTestDispatch(q, v); + } + + template + void runTestDispatchIf(Bool, QT, Tp&) { + } + + template + void runTestDispatch(Q_None, Tp& v) { + runTest(v); + } + + template + void runTestDispatch(Q_Const, Tp& v) { + runTest(v); + runTest(makeConst(v)); + } + + template + void runTestDispatch(Q_Volatile, Tp& v) { + runTest(v); + runTest(makeVolatile(v)); + + } + + template + void runTestDispatch(Q_CV, Tp& v) { + runTest(v); + runTest(makeConst(v)); + runTest(makeVolatile(v)); + runTest(makeCV(v)); + } + + template + void runTest(const std::reference_wrapper& obj) { + typedef Caster SCast; + typedef Caster ACast; + typedef CallSig (ClassType::*MemPtr); + // Delegate test to logic in invoke_helpers.h + BasicTest, Arity, SCast, ACast> b; + b.runTest( (MemPtr)&ClassType::f, obj); + } + + template + void runTest(T* obj) { + typedef Caster SCast; + typedef Caster ACast; + typedef CallSig (ClassType::*MemPtr); + // Delegate test to logic in invoke_helpers.h + BasicTest, Arity, SCast, ACast> b; + b.runTest( (MemPtr)&ClassType::f, obj); + } + + template + void runTest(Obj& obj) { + typedef Caster SCast; + typedef Caster ACast; + typedef CallSig (ClassType::*MemPtr); + // Delegate test to logic in invoke_helpers.h + BasicTest, Arity, SCast, ACast> b; + b.runTest( (MemPtr)&ClassType::f, obj); + } +}; + +template +struct TestCase : public TestCaseImp {}; + +#if TEST_STD_VER >= 11 +template +struct TestCase11 : public TestCaseImp {}; +#endif + +template +struct DerivedFromRefWrap : public std::reference_wrapper { + DerivedFromRefWrap(Tp& tp) : std::reference_wrapper(tp) {} +}; + +#if TEST_STD_VER >= 11 +void test_derived_from_ref_wrap() { + int x = 42; + std::reference_wrapper r(x); + std::reference_wrapper> r2(r); + DerivedFromRefWrap d(x); + auto get_fn = &std::reference_wrapper::get; + auto& ret = std::__invoke(get_fn, r); + assert(&ret == &x); + auto& ret2 = std::__invoke(get_fn, d); + assert(&ret2 == &x); + auto& ret3 = std::__invoke(get_fn, r2); + assert(&ret3 == &x); +} +#endif + +int main() { + typedef void*& R; + typedef ArgType A; + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + +#if TEST_STD_VER >= 11 + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + TestCase11::run(); + + test_derived_from_ref_wrap(); +#endif +} \ No newline at end of file diff --git a/libcxx/test/std/utilities/function.objects/func.require/bullet_1_and_2.pass.cpp b/libcxx/test/std/utilities/function.objects/func.require/bullet_1_and_2.pass.cpp deleted file mode 100644 index e579f207a33..00000000000 --- a/libcxx/test/std/utilities/function.objects/func.require/bullet_1_and_2.pass.cpp +++ /dev/null @@ -1,318 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// INVOKE (f, t1, t2, ..., tN) - -//------------------------------------------------------------------------------ -// TESTING INVOKE(f, t1, t2, ..., tN) -// - Bullet 1 -- (t1.*f)(t2, ..., tN) -// - Bullet 2 -- ((*t1).*f)(t2, ..., tN) -// -// Overview: -// Bullets 1 and 2 handle the case where 'f' is a pointer to member function. -// Bullet 1 only handles the cases where t1 is an object of type T or a -// type derived from 'T'. Bullet 2 handles all other cases. -// -// Concerns: -// 1) cv-qualified member function signatures are accepted. -// 2) reference qualified member function signatures are accepted. -// 3) member functions with varargs at the end are accepted. -// 4) The arguments are perfect forwarded to the member function call. -// 5) Classes that are publicly derived from 'T' are accepted as the call object -// 6) All types that dereference to T or a type derived from T can be used -// as the call object. -// 7) Pointers to T or a type derived from T can be used as the call object. -// 8) Reference return types are properly deduced. -// -// -// Plan: -// 1) Create a class that contains a set, 'S', of non-static functions. -// 'S' should include functions that cover every single combination -// of qualifiers and varargs for arities of 0, 1 and 2 (C-1,2,3). -// The argument types used in the functions should be non-copyable (C-4). -// The functions should return 'MethodID::setUncheckedCall()'. -// -// 2) Create a set of supported call object, 'Objs', of different types -// and behaviors. (C-5,6,7) -// -// 3) Attempt to call each function, 'f', in 'S' with each call object, 'c', -// in 'Objs'. After every attempted call to 'f' check that 'f' was -// actually called using 'MethodID::checkCalled()' -// -// 3b) If 'f' is reference qualified call 'f' with the properly qualified -// call object. Otherwise call 'f' with lvalue call objects. -// -// 3a) If 'f' is const, volatile, or cv qualified then call it with call -// objects that are equally or less cv-qualified. - -#include -#include -#include - -#include "test_macros.h" -#include "invoke_helpers.h" - -//============================================================================== -// MemFun03 - C++03 compatible set of test member functions. -struct MemFun03 { - typedef void*& R; -#define F(...) \ - R f(__VA_ARGS__) { return MethodID::setUncheckedCall(); } \ - R f(__VA_ARGS__) const { return MethodID::setUncheckedCall(); } \ - R f(__VA_ARGS__) volatile { return MethodID::setUncheckedCall(); } \ - R f(__VA_ARGS__) const volatile { return MethodID::setUncheckedCall(); } -# - F() - F(...) - F(ArgType&) - F(ArgType&, ...) - F(ArgType&, ArgType&) - F(ArgType&, ArgType&, ...) - F(ArgType&, ArgType&, ArgType&) - F(ArgType&, ArgType&, ArgType&, ...) -#undef F -public: - MemFun03() {} -private: - MemFun03(MemFun03 const&); - MemFun03& operator=(MemFun03 const&); -}; - - -#if TEST_STD_VER >= 11 - -//============================================================================== -// MemFun11 - C++11 reference qualified test member functions. -struct MemFun11 { - typedef void*& R; - typedef MemFun11 C; -#define F(...) \ - R f(__VA_ARGS__) & { return MethodID::setUncheckedCall(); } \ - R f(__VA_ARGS__) const & { return MethodID::setUncheckedCall(); } \ - R f(__VA_ARGS__) volatile & { return MethodID::setUncheckedCall(); } \ - R f(__VA_ARGS__) const volatile & { return MethodID::setUncheckedCall(); } \ - R f(__VA_ARGS__) && { return MethodID::setUncheckedCall(); } \ - R f(__VA_ARGS__) const && { return MethodID::setUncheckedCall(); } \ - R f(__VA_ARGS__) volatile && { return MethodID::setUncheckedCall(); } \ - R f(__VA_ARGS__) const volatile && { return MethodID::setUncheckedCall(); } -# - F() - F(...) - F(ArgType&&) - F(ArgType&&, ...) - F(ArgType&&, ArgType&&) - F(ArgType&&, ArgType&&, ...) - F(ArgType&&, ArgType&&, ArgType&&) - F(ArgType&&, ArgType&&, ArgType&&, ...) -#undef F -public: - MemFun11() {} -private: - MemFun11(MemFun11 const&); - MemFun11& operator=(MemFun11 const&); -}; - -#endif // TEST_STD_VER >= 11 - - -//============================================================================== -// TestCase - A test case for a single member function. -// ClassType - The type of the class being tested. -// CallSig - The function signature of the method being tested. -// Arity - the arity of 'CallSig' -// CV - the cv qualifiers of 'CallSig' represented as a type tag. -// RValue - The method is RValue qualified. -// ArgRValue - Call the method with RValue arguments. -template -struct TestCaseImp { -public: - - static void run() { TestCaseImp().doTest(); } - -private: - //========================================================================== - // TEST DISPATCH - void doTest() { - // (Plan-2) Create test call objects. - typedef ClassType T; - typedef DerivedFromType D; - T obj; - T* obj_ptr = &obj; - D der; - D* der_ptr = &der; - DerefToType dref; - DerefPropType dref2; - - // (Plan-3) Dispatch based on the CV tags. - CV tag; - Bool NotRValue; - runTestDispatch(tag, obj); - runTestDispatch(tag, der); - runTestDispatch(tag, dref2); - runTestDispatchIf(NotRValue, tag, dref); - runTestDispatchIf(NotRValue, tag, obj_ptr); - runTestDispatchIf(NotRValue, tag, der_ptr); - } - - template - void runTestDispatchIf(Bool, QT q, Tp& v) { - runTestDispatch(q, v); - } - - template - void runTestDispatchIf(Bool, QT, Tp&) { - } - - template - void runTestDispatch(Q_None, Tp& v) { - runTest(v); - } - - template - void runTestDispatch(Q_Const, Tp& v) { - Tp const& cv = v; - runTest(v); - runTest(cv); - } - - template - void runTestDispatch(Q_Volatile, Tp& v) { - Tp volatile& vv = v; - runTest(v); - runTest(vv); - } - - template - void runTestDispatch(Q_CV, Tp& v) { - Tp const& cv = v; - Tp volatile& vv = v; - Tp const volatile& cvv = v; - runTest(v); - runTest(cv); - runTest(vv); - runTest(cvv); - } - - template - void runTest(Obj& obj) { - typedef Caster SCast; - typedef Caster ACast; - typedef CallSig (ClassType::*MemPtr); - // Delegate test to logic in invoke_helpers.h - BasicTest, Arity, SCast, ACast> b; - b.runTest( (MemPtr)&ClassType::f, obj); - } -}; - -template -struct TestCase : public TestCaseImp {}; - -#if TEST_STD_VER >= 11 -template -struct TestCase11 : public TestCaseImp {}; -#endif - -int main() { - typedef void*& R; - typedef ArgType A; - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - -#if TEST_STD_VER >= 11 - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); - TestCase11::run(); -#endif -} \ No newline at end of file diff --git a/libcxx/test/std/utilities/function.objects/func.require/bullet_3_and_4.pass.cpp b/libcxx/test/std/utilities/function.objects/func.require/bullet_3_and_4.pass.cpp deleted file mode 100644 index b6fe190bd2a..00000000000 --- a/libcxx/test/std/utilities/function.objects/func.require/bullet_3_and_4.pass.cpp +++ /dev/null @@ -1,164 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// INVOKE (f, t1, t2, ..., tN) - -//------------------------------------------------------------------------------ -// TESTING INVOKE(f, t1, t2, ..., tN) -// - Bullet 3 -- t1.*f -// - Bullet 4 -- (*t1).*f -// -// Overview: -// Bullets 3 and 4 handle the case where 'f' is a pointer to member object. -// Bullet 3 only handles the cases where t1 is an object of type T or a -// type derived from 'T'. Bullet 4 handles all other cases. -// -// Concerns: -// 1) The return type is always an lvalue reference. -// 2) The return type is not less cv-qualified that the object that contains it. -// 3) The return type is not less cv-qualified than object type. -// 4) The call object is perfectly forwarded. -// 5) Classes that are publicly derived from 'T' are accepted as the call object -// 6) All types that dereference to T or a type derived from T can be used -// as the call object. -// 7) Pointers to T or a type derived from T can be used as the call object. - -#include -#include -#include - -#include "test_macros.h" -#include "invoke_helpers.h" - -template -struct TestMemberObject { - TestMemberObject() : object() {} - Tp object; -private: - TestMemberObject(TestMemberObject const&); - TestMemberObject& operator=(TestMemberObject const&); -}; - -template -struct TestCase { - public: - - static void run() { TestCase().doTest(); } - -private: - typedef TestMemberObject TestType; - - //========================================================================== - // TEST DISPATCH - void doTest() { - typedef DerivedFromType Derived; - TestType obj; - TestType* obj_ptr = &obj; - Derived der; - Derived* der_ptr = &der; - DerefToType dref; - DerefPropType dref2; - - { - typedef ObjectType (TestType::*MemPtr); - typedef ObjectType E; - MemPtr M = &TestType::object; - runTestDispatch(M, obj, &obj.object); - runTestDispatch(M, der, &der.object); - runTestDispatch(M, dref2, &dref2.object.object); - runTestPointerDispatch(M, obj_ptr, &obj_ptr->object); - runTestPointerDispatch(M, der_ptr, &der_ptr->object); - runTestPointerDispatch(M, dref, &dref.object.object); - } - { - typedef ObjectType const (TestType::*CMemPtr); - typedef ObjectType const E; - CMemPtr M = &TestType::object; - runTestDispatch(M, obj, &obj.object); - runTestDispatch(M, der, &der.object); - runTestDispatch(M, dref2, &dref2.object.object); - runTestPointerDispatch(M, obj_ptr, &obj_ptr->object); - runTestPointerDispatch(M, der_ptr, &der_ptr->object); - runTestPointerDispatch(M, dref, &dref.object.object); - } - { - typedef ObjectType volatile (TestType::*VMemPtr); - typedef ObjectType volatile E; - VMemPtr M = &TestType::object; - runTestDispatch(M, obj, &obj.object); - runTestDispatch(M, der, &der.object); - runTestDispatch(M, dref2, &dref2.object.object); - runTestPointerDispatch(M, obj_ptr, &obj_ptr->object); - runTestPointerDispatch(M, der_ptr, &der_ptr->object); - runTestPointerDispatch(M, dref, &dref.object.object); - } - { - typedef ObjectType const volatile (TestType::*CVMemPtr); - typedef ObjectType const volatile E; - CVMemPtr M = &TestType::object; - runTestDispatch(M, obj, &obj.object); - runTestDispatch(M, der, &der.object); - runTestDispatch(M, dref2, &dref2.object.object); - runTestPointerDispatch(M, obj_ptr, &obj_ptr->object); - runTestPointerDispatch(M, der_ptr, &der_ptr->object); - runTestPointerDispatch(M, dref, &dref.object.object); - } - } - - template - void runTestDispatch(Fn M, T& obj, ObjectType* expect) { - runTest (M, C_(obj), expect); - runTest (M, C_(obj), expect); - runTest (M, C_(obj), expect); - runTest(M, C_(obj), expect); -#if TEST_STD_VER >= 11 - runTest (M, C_(obj), expect); - runTest (M, C_(obj), expect); - runTest (M, C_(obj), expect); - runTest(M, C_(obj), expect); -#endif - } - - template - void runTestPointerDispatch(Fn M, T& obj, ObjectType* expect) { - runTest(M, C_(obj), expect); - runTest(M, C_(obj), expect); - runTest(M, C_(obj), expect); - runTest(M, C_(obj), expect); -#if TEST_STD_VER >= 11 - runTest(M, C_(obj), expect); - runTest(M, C_(obj), expect); - runTest(M, C_(obj), expect); - runTest(M, C_(obj), expect); -#endif - } - - template -#if TEST_STD_VER >= 11 - void runTest(Fn M, T&& obj, ObjectType* expect) { -#else - void runTest(Fn M, T& obj, ObjectType* expect ) { -#endif - static_assert((std::is_same< - decltype(std::__invoke(M, std::forward(obj))), Expect - >::value), ""); - Expect e = std::__invoke(M, std::forward(obj)); - assert(&e == expect); - } -}; - -int main() { - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); - TestCase::run(); -} \ No newline at end of file diff --git a/libcxx/test/std/utilities/function.objects/func.require/bullet_4_5_6.pass.cpp b/libcxx/test/std/utilities/function.objects/func.require/bullet_4_5_6.pass.cpp new file mode 100644 index 00000000000..2007c417a62 --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/func.require/bullet_4_5_6.pass.cpp @@ -0,0 +1,205 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// INVOKE (f, t1, t2, ..., tN) + +//------------------------------------------------------------------------------ +// TESTING INVOKE(f, t1, t2, ..., tN) +// - Bullet 4 -- t1.*f +// - Bullet 5 -- t1.get().*f // t1 is a reference wrapper. +// - Bullet 6 -- (*t1).*f +// +// Overview: +// Bullets 4, 5 and 6 handle the case where 'f' is a pointer to member object. +// Bullet 4 only handles the cases where t1 is an object of type T or a +// type derived from 'T'. Bullet 5 handles cases where 't1' is a reference_wrapper +// and bullet 6 handles all other cases. +// +// Concerns: +// 1) The return type is always an lvalue reference. +// 2) The return type is not less cv-qualified that the object that contains it. +// 3) The return type is not less cv-qualified than object type. +// 4) The call object is perfectly forwarded. +// 5) Classes that are publicly derived from 'T' are accepted as the call object +// 6) All types that dereference to T or a type derived from T can be used +// as the call object. +// 7) Pointers to T or a type derived from T can be used as the call object. +// 8) reference_wrapper's are properly unwrapped before invoking the function. + +#include +#include +#include + +#include "test_macros.h" +#include "invoke_helpers.h" + +template +struct TestMemberObject { + TestMemberObject() : object() {} + Tp object; +private: + TestMemberObject(TestMemberObject const&); + TestMemberObject& operator=(TestMemberObject const&); +}; + +template +struct TestCase { + public: + + static void run() { TestCase().doTest(); } + +private: + typedef TestMemberObject TestType; + + //========================================================================== + // TEST DISPATCH + void doTest() { + typedef DerivedFromType Derived; + TestType obj; + TestType* obj_ptr = &obj; + Derived der; + Derived* der_ptr = &der; + DerefToType dref; + DerefPropType dref2; + std::reference_wrapper rref(obj); + std::reference_wrapper drref(der); + + { + typedef ObjectType (TestType::*MemPtr); + typedef ObjectType E; + MemPtr M = &TestType::object; + runTestDispatch(M, obj, &obj.object); + runTestDispatch(M, der, &der.object); + runTestDispatch(M, dref2, &dref2.object.object); + runTestPropCVDispatch(M, obj_ptr, &obj_ptr->object); + runTestPropCVDispatch(M, der_ptr, &der_ptr->object); +#if TEST_STD_VER >= 11 + runTestPropCVDispatch(M, rref, &(rref.get().object)); + runTestPropCVDispatch(M, drref, &(drref.get().object)); +#endif + runTestNoPropDispatch(M, dref, &dref.object.object); + } + { + typedef ObjectType const (TestType::*CMemPtr); + typedef ObjectType const E; + CMemPtr M = &TestType::object; + runTestDispatch(M, obj, &obj.object); + runTestDispatch(M, der, &der.object); + runTestDispatch(M, dref2, &dref2.object.object); + runTestPropCVDispatch(M, obj_ptr, &obj_ptr->object); + runTestPropCVDispatch(M, der_ptr, &der_ptr->object); +#if TEST_STD_VER >= 11 + runTestPropCVDispatch(M, rref, &(rref.get().object)); + runTestPropCVDispatch(M, drref, &(drref.get().object)); +#endif + runTestNoPropDispatch(M, dref, &dref.object.object); + } + { + typedef ObjectType volatile (TestType::*VMemPtr); + typedef ObjectType volatile E; + VMemPtr M = &TestType::object; + runTestDispatch(M, obj, &obj.object); + runTestDispatch(M, der, &der.object); + runTestDispatch(M, dref2, &dref2.object.object); + runTestPropCVDispatch(M, obj_ptr, &obj_ptr->object); + runTestPropCVDispatch(M, der_ptr, &der_ptr->object); +#if TEST_STD_VER >= 11 + runTestPropCVDispatch(M, rref, &(rref.get().object)); + runTestPropCVDispatch(M, drref, &(drref.get().object)); +#endif + runTestNoPropDispatch(M, dref, &dref.object.object); + } + { + typedef ObjectType const volatile (TestType::*CVMemPtr); + typedef ObjectType const volatile E; + CVMemPtr M = &TestType::object; + runTestDispatch(M, obj, &obj.object); + runTestDispatch(M, der, &der.object); + runTestDispatch(M, dref2, &dref2.object.object); + runTestPropCVDispatch(M, obj_ptr, &obj_ptr->object); + runTestPropCVDispatch(M, der_ptr, &der_ptr->object); +#if TEST_STD_VER >= 11 + runTestPropCVDispatch(M, rref, &(rref.get().object)); + runTestPropCVDispatch(M, drref, &(drref.get().object)); +#endif + runTestNoPropDispatch(M, dref, &dref.object.object); + } + } + + template + void runTestDispatch(Fn M, T& obj, ObjectType* expect) { + runTest (M, C_(obj), expect); + runTest (M, C_(obj), expect); + runTest (M, C_(obj), expect); + runTest(M, C_(obj), expect); +#if TEST_STD_VER >= 11 + runTest (M, C_(obj), expect); + runTest (M, C_(obj), expect); + runTest (M, C_(obj), expect); + runTest(M, C_(obj), expect); +#endif + } + + template + void runTestPropCVDispatch(Fn M, T& obj, ObjectType* expect) { + runTest (M, obj, expect); + runTest (M, makeConst(obj), expect); + runTest (M, makeVolatile(obj), expect); + runTest(M, makeCV(obj), expect); + } + + template + void runTestNoPropDispatch(Fn M, T& obj, ObjectType* expect) { + runTest(M, C_(obj), expect); + runTest(M, C_(obj), expect); + runTest(M, C_(obj), expect); + runTest(M, C_(obj), expect); +#if TEST_STD_VER >= 11 + runTest(M, C_(obj), expect); + runTest(M, C_(obj), expect); + runTest(M, C_(obj), expect); + runTest(M, C_(obj), expect); +#endif + } + + template + void runTest(Fn M, const T& obj, ObjectType* expect) { + static_assert((std::is_same< + decltype(std::__invoke(M, obj)), Expect + >::value), ""); + Expect e = std::__invoke(M, obj); + assert(&e == expect); + } + + template +#if TEST_STD_VER >= 11 + void runTest(Fn M, T&& obj, ObjectType* expect) { +#else + void runTest(Fn M, T& obj, ObjectType* expect ) { +#endif + static_assert((std::is_same< + decltype(std::__invoke(M, std::forward(obj))), Expect + >::value), ""); + Expect e = std::__invoke(M, std::forward(obj)); + assert(&e == expect); + } +}; + + + + +int main() { + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); + TestCase::run(); +} \ No newline at end of file diff --git a/libcxx/test/std/utilities/function.objects/func.require/bullet_5.pass.cpp b/libcxx/test/std/utilities/function.objects/func.require/bullet_5.pass.cpp deleted file mode 100644 index 3f3c96a9b9b..00000000000 --- a/libcxx/test/std/utilities/function.objects/func.require/bullet_5.pass.cpp +++ /dev/null @@ -1,327 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// INVOKE (f, t1, t2, ..., tN) - -//------------------------------------------------------------------------------ -// TESTING INVOKE(f, t1, t2, ..., tN) -// - Bullet 5 -- f(t2, ..., tN) -// -// Overview: -// Bullet 5 handles the cases where the first argument is not a member -// function. -// -// Concerns: -// 1) Different types of callable objects are supported. Including -// 1a) Free Function pointers and references. -// 1b) Classes which provide a call operator -// 1c) lambdas -// 2) The callable objects are perfect forwarded. -// 3) The arguments are perfect forwarded. -// 4) Signatures which include varargs are supported. -// 5) In C++03 3 extra arguments should be allowed. -// -// Plan: -// 1) Define a set of free functions, 'SF', and class types with call -// operators, 'SC', that address concerns 4 and 5. The free functions should -// return 'FunctionID::setUncheckedCall()' and the call operators should -// return 'MethodID::setUncheckedCall()'. -// -// 2) For each function 'f' in 'SF' and 'SC' attempt to call 'f' -// using the correct number of arguments and cv-ref qualifiers. Check that -// 'f' has been called using 'FunctionID::checkCall()' if 'f' is a free -// function and 'MethodID::checkCall()' otherwise. - - - -#include -#include -#include - -#include "test_macros.h" -#include "invoke_helpers.h" - - -//============================================================================== -// freeFunction03 - A C++03 free function. -void*& freeFunction03() { - return FunctionPtrID::setUncheckedCall(); -} - -void*& freeFunction03(...) { - return FunctionPtrID::setUncheckedCall(); -} - -template -void*& freeFunction03(A0&) { - return FunctionPtrID::setUncheckedCall(); -} - - -template -void*& freeFunction03(A0&, ...) { - return FunctionPtrID::setUncheckedCall(); -} - -template -void*& freeFunction03(A0&, A1&) { - return FunctionPtrID::setUncheckedCall(); -} - - -template -void*& freeFunction03(A0&, A1&, ...) { - return FunctionPtrID::setUncheckedCall(); -} - -template -void*& freeFunction03(A0&, A1&, A2&) { - return FunctionPtrID::setUncheckedCall(); -} - -template -void*& freeFunction03(A0&, A1&, A2&, ...) { - return FunctionPtrID::setUncheckedCall(); -} - -//============================================================================== -// Functor03 - C++03 compatible functor object -struct Functor03 { - typedef void*& R; - typedef Functor03 C; -#define F(Args, ...) \ - __VA_ARGS__ R operator() Args { return MethodID::setUncheckedCall(); } \ - __VA_ARGS__ R operator() Args const { return MethodID::setUncheckedCall(); } \ - __VA_ARGS__ R operator() Args volatile { return MethodID::setUncheckedCall(); } \ - __VA_ARGS__ R operator() Args const volatile { return MethodID::setUncheckedCall(); } -# - F(()) - F((A0&), template ) - F((A0&, A1&), template ) - F((A0&, A1&, A2&), template ) -#undef F -public: - Functor03() {} -private: - Functor03(Functor03 const&); - Functor03& operator=(Functor03 const&); -}; - - -#if TEST_STD_VER >= 11 - -//============================================================================== -// freeFunction11 - A C++11 free function. -template -void*& freeFunction11(Args&&...) { - return FunctionPtrID::setUncheckedCall(); -} - -template -void*& freeFunction11(Args&&...,...) { - return FunctionPtrID::setUncheckedCall(); -} - -//============================================================================== -// Functor11 - C++11 reference qualified test member functions. -struct Functor11 { - typedef void*& R; - typedef Functor11 C; - -#define F(CV) \ - template \ - R operator()(Args&&...) CV { return MethodID::setUncheckedCall(); } -# - F(&) - F(const &) - F(volatile &) - F(const volatile &) - F(&&) - F(const &&) - F(volatile &&) - F(const volatile &&) -#undef F -public: - Functor11() {} -private: - Functor11(Functor11 const&); - Functor11& operator=(Functor11 const&); -}; - -#endif // TEST_STD_VER >= 11 - - -//============================================================================== -// TestCaseFunctorImp - A test case for an operator() class method. -// ClassType - The type of the call object. -// CallSig - The function signature of the call operator being tested. -// Arity - the arity of 'CallSig' -// ObjCaster - Transformation function applied to call object. -// ArgCaster - Transformation function applied to the extra arguments. -template -struct TestCaseFunctorImp { -public: - static void run() { - typedef MethodID MID; - BasicTest t; - typedef ClassType T; - typedef DerivedFromType D; - T obj; - D der; - t.runTest(obj); - t.runTest(der); - } -}; - -//============================================================================== -// TestCaseFreeFunction - A test case for a free function. -// CallSig - The function signature of the free function being tested. -// FnPtr - The function being tested. -// Arity - the arity of 'CallSig' -// ArgCaster - Transformation function to be applied to the extra arguments. -template -struct TestCaseFreeFunction { -public: - static void run() { - typedef FunctionPtrID FID; - BasicTest t; - - DerefToType deref_to(FnPtr); - DerefToType deref_to_ref(*FnPtr); - - t.runTest(FnPtr); - t.runTest(*FnPtr); - t.runTest(deref_to); - t.runTest(deref_to_ref); - } -}; - -//============================================================================== -// runTest Helpers -//============================================================================== -#if TEST_STD_VER >= 11 -template -void runFunctionTestCase11() { - TestCaseFreeFunction(); -} -#endif - -template -void runFunctionTestCase() { - TestCaseFreeFunction(); -#if TEST_STD_VER >= 11 - runFunctionTestCase11(); -#endif -} - -template -void runFunctorTestCase() { - TestCaseFunctorImp::run(); -} - -template -void runFunctorTestCase() { - TestCaseFunctorImp::run(); -} - -#if TEST_STD_VER >= 11 -// runTestCase - Run a test case for C++11 class functor types -template -void runFunctorTestCase11() { - TestCaseFunctorImp::run(); -} -#endif - -// runTestCase - Run a test case for both function and functor types. -template -void runTestCase() { - runFunctionTestCase(); - runFunctorTestCase (); -}; - -int main() { - typedef void*& R; - typedef ArgType A; - typedef A const CA; - - runTestCase< R(), 0, LValueCaster >(); - runTestCase< R(A&), 1, LValueCaster >(); - runTestCase< R(A&, A&), 2, LValueCaster >(); - runTestCase< R(A&, A&, A&), 3, LValueCaster >(); - runTestCase< R(CA&), 1, ConstCaster >(); - runTestCase< R(CA&, CA&), 2, ConstCaster >(); - runTestCase< R(CA&, CA&, CA&), 3, ConstCaster >(); - - runFunctionTestCase(); - runFunctionTestCase(); - runFunctionTestCase(); - runFunctionTestCase(); - -#if TEST_STD_VER >= 11 - runFunctionTestCase11(); - runFunctionTestCase11(); -#endif - - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - { - typedef ConstCaster CC; - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - runFunctorTestCase(); - } - -#if TEST_STD_VER >= 11 - runFunctorTestCase11(); - runFunctorTestCase11(); - runFunctorTestCase11(); - runFunctorTestCase11(); - runFunctorTestCase11(); - runFunctorTestCase11(); - runFunctorTestCase11(); - runFunctorTestCase11(); - { - typedef MoveCaster MC; - runFunctorTestCase11(); - runFunctorTestCase11(); - runFunctorTestCase11(); - runFunctorTestCase11(); - runFunctorTestCase11(); - runFunctorTestCase11(); - runFunctorTestCase11(); - runFunctorTestCase11(); - } -#endif -} diff --git a/libcxx/test/std/utilities/function.objects/func.require/bullet_7.pass.cpp b/libcxx/test/std/utilities/function.objects/func.require/bullet_7.pass.cpp new file mode 100644 index 00000000000..0d14a350c89 --- /dev/null +++ b/libcxx/test/std/utilities/function.objects/func.require/bullet_7.pass.cpp @@ -0,0 +1,327 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// INVOKE (f, t1, t2, ..., tN) + +//------------------------------------------------------------------------------ +// TESTING INVOKE(f, t1, t2, ..., tN) +// - Bullet 7 -- f(t2, ..., tN) +// +// Overview: +// Bullet 7 handles the cases where the first argument is not a member +// function. +// +// Concerns: +// 1) Different types of callable objects are supported. Including +// 1a) Free Function pointers and references. +// 1b) Classes which provide a call operator +// 1c) lambdas +// 2) The callable objects are perfect forwarded. +// 3) The arguments are perfect forwarded. +// 4) Signatures which include varargs are supported. +// 5) In C++03 3 extra arguments should be allowed. +// +// Plan: +// 1) Define a set of free functions, 'SF', and class types with call +// operators, 'SC', that address concerns 4 and 5. The free functions should +// return 'FunctionID::setUncheckedCall()' and the call operators should +// return 'MethodID::setUncheckedCall()'. +// +// 2) For each function 'f' in 'SF' and 'SC' attempt to call 'f' +// using the correct number of arguments and cv-ref qualifiers. Check that +// 'f' has been called using 'FunctionID::checkCall()' if 'f' is a free +// function and 'MethodID::checkCall()' otherwise. + + + +#include +#include +#include + +#include "test_macros.h" +#include "invoke_helpers.h" + + +//============================================================================== +// freeFunction03 - A C++03 free function. +void*& freeFunction03() { + return FunctionPtrID::setUncheckedCall(); +} + +void*& freeFunction03(...) { + return FunctionPtrID::setUncheckedCall(); +} + +template +void*& freeFunction03(A0&) { + return FunctionPtrID::setUncheckedCall(); +} + + +template +void*& freeFunction03(A0&, ...) { + return FunctionPtrID::setUncheckedCall(); +} + +template +void*& freeFunction03(A0&, A1&) { + return FunctionPtrID::setUncheckedCall(); +} + + +template +void*& freeFunction03(A0&, A1&, ...) { + return FunctionPtrID::setUncheckedCall(); +} + +template +void*& freeFunction03(A0&, A1&, A2&) { + return FunctionPtrID::setUncheckedCall(); +} + +template +void*& freeFunction03(A0&, A1&, A2&, ...) { + return FunctionPtrID::setUncheckedCall(); +} + +//============================================================================== +// Functor03 - C++03 compatible functor object +struct Functor03 { + typedef void*& R; + typedef Functor03 C; +#define F(Args, ...) \ + __VA_ARGS__ R operator() Args { return MethodID::setUncheckedCall(); } \ + __VA_ARGS__ R operator() Args const { return MethodID::setUncheckedCall(); } \ + __VA_ARGS__ R operator() Args volatile { return MethodID::setUncheckedCall(); } \ + __VA_ARGS__ R operator() Args const volatile { return MethodID::setUncheckedCall(); } +# + F(()) + F((A0&), template ) + F((A0&, A1&), template ) + F((A0&, A1&, A2&), template ) +#undef F +public: + Functor03() {} +private: + Functor03(Functor03 const&); + Functor03& operator=(Functor03 const&); +}; + + +#if TEST_STD_VER >= 11 + +//============================================================================== +// freeFunction11 - A C++11 free function. +template +void*& freeFunction11(Args&&...) { + return FunctionPtrID::setUncheckedCall(); +} + +template +void*& freeFunction11(Args&&...,...) { + return FunctionPtrID::setUncheckedCall(); +} + +//============================================================================== +// Functor11 - C++11 reference qualified test member functions. +struct Functor11 { + typedef void*& R; + typedef Functor11 C; + +#define F(CV) \ + template \ + R operator()(Args&&...) CV { return MethodID::setUncheckedCall(); } +# + F(&) + F(const &) + F(volatile &) + F(const volatile &) + F(&&) + F(const &&) + F(volatile &&) + F(const volatile &&) +#undef F +public: + Functor11() {} +private: + Functor11(Functor11 const&); + Functor11& operator=(Functor11 const&); +}; + +#endif // TEST_STD_VER >= 11 + + +//============================================================================== +// TestCaseFunctorImp - A test case for an operator() class method. +// ClassType - The type of the call object. +// CallSig - The function signature of the call operator being tested. +// Arity - the arity of 'CallSig' +// ObjCaster - Transformation function applied to call object. +// ArgCaster - Transformation function applied to the extra arguments. +template +struct TestCaseFunctorImp { +public: + static void run() { + typedef MethodID MID; + BasicTest t; + typedef ClassType T; + typedef DerivedFromType D; + T obj; + D der; + t.runTest(obj); + t.runTest(der); + } +}; + +//============================================================================== +// TestCaseFreeFunction - A test case for a free function. +// CallSig - The function signature of the free function being tested. +// FnPtr - The function being tested. +// Arity - the arity of 'CallSig' +// ArgCaster - Transformation function to be applied to the extra arguments. +template +struct TestCaseFreeFunction { +public: + static void run() { + typedef FunctionPtrID FID; + BasicTest t; + + DerefToType deref_to(FnPtr); + DerefToType deref_to_ref(*FnPtr); + + t.runTest(FnPtr); + t.runTest(*FnPtr); + t.runTest(deref_to); + t.runTest(deref_to_ref); + } +}; + +//============================================================================== +// runTest Helpers +//============================================================================== +#if TEST_STD_VER >= 11 +template +void runFunctionTestCase11() { + TestCaseFreeFunction(); +} +#endif + +template +void runFunctionTestCase() { + TestCaseFreeFunction(); +#if TEST_STD_VER >= 11 + runFunctionTestCase11(); +#endif +} + +template +void runFunctorTestCase() { + TestCaseFunctorImp::run(); +} + +template +void runFunctorTestCase() { + TestCaseFunctorImp::run(); +} + +#if TEST_STD_VER >= 11 +// runTestCase - Run a test case for C++11 class functor types +template +void runFunctorTestCase11() { + TestCaseFunctorImp::run(); +} +#endif + +// runTestCase - Run a test case for both function and functor types. +template +void runTestCase() { + runFunctionTestCase(); + runFunctorTestCase (); +}; + +int main() { + typedef void*& R; + typedef ArgType A; + typedef A const CA; + + runTestCase< R(), 0, LValueCaster >(); + runTestCase< R(A&), 1, LValueCaster >(); + runTestCase< R(A&, A&), 2, LValueCaster >(); + runTestCase< R(A&, A&, A&), 3, LValueCaster >(); + runTestCase< R(CA&), 1, ConstCaster >(); + runTestCase< R(CA&, CA&), 2, ConstCaster >(); + runTestCase< R(CA&, CA&, CA&), 3, ConstCaster >(); + + runFunctionTestCase(); + runFunctionTestCase(); + runFunctionTestCase(); + runFunctionTestCase(); + +#if TEST_STD_VER >= 11 + runFunctionTestCase11(); + runFunctionTestCase11(); +#endif + + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + { + typedef ConstCaster CC; + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + runFunctorTestCase(); + } + +#if TEST_STD_VER >= 11 + runFunctorTestCase11(); + runFunctorTestCase11(); + runFunctorTestCase11(); + runFunctorTestCase11(); + runFunctorTestCase11(); + runFunctorTestCase11(); + runFunctorTestCase11(); + runFunctorTestCase11(); + { + typedef MoveCaster MC; + runFunctorTestCase11(); + runFunctorTestCase11(); + runFunctorTestCase11(); + runFunctorTestCase11(); + runFunctorTestCase11(); + runFunctorTestCase11(); + runFunctorTestCase11(); + runFunctorTestCase11(); + } +#endif +} diff --git a/libcxx/test/std/utilities/function.objects/func.require/invoke_helpers.h b/libcxx/test/std/utilities/function.objects/func.require/invoke_helpers.h index a85b39f3717..495703d0e32 100644 --- a/libcxx/test/std/utilities/function.objects/func.require/invoke_helpers.h +++ b/libcxx/test/std/utilities/function.objects/func.require/invoke_helpers.h @@ -79,6 +79,40 @@ typedef Caster MoveConstCaster; typedef Caster MoveVolatileCaster; typedef Caster MoveCVCaster; + +template +Tp const& makeConst(Tp& ref) { return ref; } + +template +Tp const* makeConst(Tp* ptr) { return ptr; } + +template +std::reference_wrapper makeConst(std::reference_wrapper& ref) { + return std::reference_wrapper(ref.get()); +} + +template +Tp volatile& makeVolatile(Tp& ref) { return ref; } + +template +Tp volatile* makeVolatile(Tp* ptr) { return ptr; } + +template +std::reference_wrapper makeVolatile(std::reference_wrapper& ref) { + return std::reference_wrapper(ref.get()); +} + +template +Tp const volatile& makeCV(Tp& ref) { return ref; } + +template +Tp const volatile* makeCV(Tp* ptr) { return ptr; } + +template +std::reference_wrapper makeCV(std::reference_wrapper& ref) { + return std::reference_wrapper(ref.get()); +} + // A shorter name for 'static_cast' template QualType C_(Tp& v) { return static_cast(v); }; -- cgit v1.2.3