openbmc / sdbusplus

C++ bindings for systemd dbus APIs
Apache License 2.0
104 stars 82 forks source link

sdbus++ generates invalid code for methods without return value #3

Closed milindur closed 7 years ago

milindur commented 7 years ago

When defining an interface with a method without return value, e.g.

description: >
    An example interface
methods:
    - name: ping
      description: >
        Takes a string argument and returns nothing.
      parameters:
        - name: name
          type: string
          description: >
            The string argument.

the sdbus++ tool generates invalid code:

namespace details
{
namespace TestService
{
static const auto _param_Ping =
        utility::tuple_to_array(message::types::type_id<
                std::string>());
static const auto _return_Ping =
        utility::tuple_to_array(message::types::type_id<
                >());
}
}

_return_Ping has no associated type list. The error is

/home/anders05/Dev/sdbusplus/sdbusplus/message/types.hpp:198:72: error: no matching function for call to ‘type_id_multiple()’
         details::type_id_multiple<details::type_id_downcast_t<Args>...>(),
                                                                        ^
/home/anders05/Dev/sdbusplus/sdbusplus/message/types.hpp:187:56: note: candidate: template<class T, class ... Args> constexpr auto sdbusplus::message::types::details::type_id_multiple()
 template <typename T, typename ...Args> constexpr auto type_id_multiple()
                                                        ^
/home/anders05/Dev/sdbusplus/sdbusplus/message/types.hpp:187:56: note:   template argument deduction/substitution failed:
/home/anders05/Dev/sdbusplus/sdbusplus/message/types.hpp:198:72: note:   couldn't deduce template parameter ‘T’
         details::type_id_multiple<details::type_id_downcast_t<Args>...>(),
                                                                        ^
/home/anders05/Dev/dbus-examples/sdbusplus/src/.../.../.../TestService/server.cpp:64:20: error: invalid use of void expression
                 >());
williamspatrick commented 7 years ago

Interesting. The sample has a function with neither parameters nor returns and it generates this:

namespace details
{
namespace Calculator
{
static const auto _param_Clear =
        utility::tuple_to_array(std::make_tuple('\0'));
static const auto _return_Clear =
        utility::tuple_to_array(std::make_tuple('\0'));
}
}

I'll look into what goes wrong when we put a single parameter in place. I'm observing the same.

williamspatrick commented 7 years ago

Found it.

namespace details
{
namespace ${interface_name()}
{
static const auto _param_${ method.CamelCase } =
    % if len(method.parameters) == 0:
        utility::tuple_to_array(std::make_tuple('\0'));
    % else:
        utility::tuple_to_array(message::types::type_id<
                ${ parameters_types_as_list() }>());
    % endif
static const auto _return_${ method.CamelCase } =
    % if len(method.parameters) == 0:    <------ oops!
        utility::tuple_to_array(std::make_tuple('\0'));
    % else:
        utility::tuple_to_array(message::types::type_id<
                ${ returns_as_list(as_param=False) }>());
    % endif
}
}
williamspatrick commented 7 years ago

Fix here:

remote:   https://gerrit.openbmc-project.xyz/1260 sdbus++: generate valid code 0 return methods
milindur commented 7 years ago

Thanks, now it's working for me, too.