From ae01928016f2983aa44f1279a2575572514953f7 Mon Sep 17 00:00:00 2001 From: Patrick Williams Date: Sat, 4 Nov 2023 08:27:32 -0500 Subject: [PATCH] async: client: avoid ambiguous base-class error When using multiple generated client classes with client_t, we can end up with an ambiguous base-class error. Change the way the `client_context_friend` utility derives the context pointer from the `Client` template type, to avoid the ambiguity. Previous failure when inheriting both `state::BMC` and `state::Host` into a single `client_t`: ``` error: 'sdbusplus::async::client::details::client_context_friend' is an ambiguous base of 'sdbusplus::async::client::client' return static_cast(this)->ctx; ``` Signed-off-by: Patrick Williams Change-Id: I047f00ca8df071eef13e8fdd71a56910cc7b3e26 --- include/sdbusplus/async/client.hpp | 6 +++--- tools/sdbusplus/templates/interface.client.hpp.mako | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/sdbusplus/async/client.hpp b/include/sdbusplus/async/client.hpp index 25bba410..44f45655 100644 --- a/include/sdbusplus/async/client.hpp +++ b/include/sdbusplus/async/client.hpp @@ -95,10 +95,10 @@ namespace client::details */ struct client_context_friend { - template - sdbusplus::async::context& context() + template + static sdbusplus::async::context& context(Self* self) { - return static_cast(this)->ctx; + return static_cast(self)->ctx; } }; } // namespace client::details diff --git a/tools/sdbusplus/templates/interface.client.hpp.mako b/tools/sdbusplus/templates/interface.client.hpp.mako index 7963a53b..e1ec282f 100644 --- a/tools/sdbusplus/templates/interface.client.hpp.mako +++ b/tools/sdbusplus/templates/interface.client.hpp.mako @@ -44,7 +44,7 @@ namespace details template class ${interface.classname} : public sdbusplus::common::${interface.cppNamespacedClass()}, - public sdbusplus::async::client::details::client_context_friend + private sdbusplus::async::client::details::client_context_friend { public: friend Client; @@ -70,7 +70,7 @@ ${p.render(loader, "property.client.hpp.mako", property=p, interface=interface)} sdbusplus::async::context& context() { return sdbusplus::async::client::details::client_context_friend:: - context(); + context(this); } decltype(std::declval().interface(interface)) proxy = {};