//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // 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 #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&); }; //============================================================================== // 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); } 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 {}; int main(int, char**) { 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(); return 0; }