//===----------------------------------------------------------------------===// // // 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 }