skypjack / entt

Gaming meets modern C++ - a fast and reliable entity component system (ECS) and much more
https://github.com/skypjack/entt/wiki
MIT License
10.01k stars 877 forks source link

meta: data function fails if setter is noexcept #1167

Closed mathisloge closed 1 week ago

mathisloge commented 3 weeks ago

Given the following code

struct Test
{
  public:
    int x() const
    {
        return x_;
    }
    void setX(int newx) noexcept
    {
        x_ = newx;
    }

  private:
    int x_;
};

entt::meta<Test>().data<&Test::setX, &Test::x>("x"_hs); // won't compile

If void setX(int newx) is noexcept(true) the using args_type = entt::meta_function_helper_t<Test, decltype(&Test::setX)>::args_type; can't resolve the arguments from setX, since somehow the get_rid_of_noexcept doesn't work.

As soon as I remove the noexcept, the code compiles again.

entt version: 3.13.2

skypjack commented 3 weeks ago

It was harder to figure it out than to fix it. Good catch! The issue is due to the support for member objects. That overload of get_rid_of_noexcept should only be conditionally enabled. Otherwise, it's a better match than the one where decaying the function type is required.

skypjack commented 3 weeks ago

A fix is available on the wip branch. Can you confirm that it solves your issue? The snippet above works fine with it. Not sure if the same applies to your real world case though. Thanks.

mathisloge commented 3 weeks ago

Hi,

I've tested it and it works now as expected. Thanks for fixing this so fast! :)

skypjack commented 3 weeks ago

Thanks for pointing it out. It was a subtle issue actually. I'll include the fix in the upcoming minor release rather than making a new patch release.