From 1acad98f7d162ee4e9d5f869489b0c3b17ad80aa Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 3 Jan 2020 01:42:51 +0200 Subject: libcamera: object: Support reference arguments in invokeMethod() Invoking a method that takes a reference argument with Object::invokeMethod() results in a compilation error: ../test/object-invoke.cpp:131:11: error: no matching member function for call to 'invokeMethod' object_.invokeMethod(&InvokedObject::methodWithReference, ~~~~~~~~^~~~~~~~~~~~ ../include/libcamera/object.h:33:7: note: candidate template ignored: deduced conflicting types for parameter 'Args' ( vs. ) void invokeMethod(void (T::*func)(Args...), ConnectionType type, Args... args) This is due to the fact that implicit type conversions (from value to reference in this case) takes place after template argument type deduction, during overload resolution. A similar issue would occur if T::func took a long argument and invokeMethod() was called with an in argument. Fix this by specifying to sets of argument types in the invokeMethod() template, one for the arguments to the invoked method, and one for the arguments to invokeMethod() itself. The compiler can then first perform type deduction separately, and implicit conversion in a second step. Reported-by: Paul Elder Signed-off-by: Laurent Pinchart Reviewed-by: Paul Elder Reviewed-by: Jacopo Mondi --- include/libcamera/object.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/libcamera/object.h b/include/libcamera/object.h index 86e0f726..21b70460 100644 --- a/include/libcamera/object.h +++ b/include/libcamera/object.h @@ -29,13 +29,15 @@ public: void postMessage(std::unique_ptr msg); - template::value>::type * = nullptr> - void invokeMethod(void (T::*func)(Args...), ConnectionType type, Args... args) + template::value>::type * = nullptr> + void invokeMethod(void (T::*func)(FuncArgs...), ConnectionType type, + Args... args) { T *obj = static_cast(this); BoundMethodBase *method = - new BoundMemberMethod(obj, this, func, type); - void *pack = new typename BoundMemberMethod::PackType{ args... }; + new BoundMemberMethod(obj, this, func, type); + void *pack = new typename BoundMemberMethod::PackType{ args... }; method->activatePack(pack, true); } -- cgit v1.2.1