From patchwork Thu Jan 2 23:53:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2484 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7EAB660469 for ; Fri, 3 Jan 2020 00:53:25 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1AA7E9A5 for ; Fri, 3 Jan 2020 00:53:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1578009205; bh=XvyIQc2YGGrvrBKw69hPk6jZi/Ge2LUwEmcv43pmvL4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pLrAluxUBFYmhAX6ELIpHnnPQmbZDTWyLtOC4+vfTcAlEgLri/m6WuQ8EyN0fTrdl WOrf9M6Pgb+5kYfeYGHTvOYFaj/RbfOTqwcwIQIzujtsCEDv8YW2fdwm33tIC8yl2B IPPintOO7B5gMX2+3xeMHKDbCO2bKsrwAudn7wzw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Jan 2020 01:53:11 +0200 Message-Id: <20200102235311.12009-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102235311.12009-1-laurent.pinchart@ideasonboard.com> References: <20200102235311.12009-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] libcamera: object: Support reference arguments in invokeMethod() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Jan 2020 23:53:25 -0000 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(-) diff --git a/include/libcamera/object.h b/include/libcamera/object.h index 86e0f7265865..21b70460b516 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); }