Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factory with of object with shared_ptr parameter not compiling on gcc 13.2.1 and gcc 12.2.1 #559

Open
sva522 opened this issue Feb 12, 2024 · 0 comments

Comments

@sva522
Copy link

sva522 commented Feb 12, 2024

Dear,

This code is working fine :

#include <boost/di/extension/injections/factory.hpp>
#include <cassert>
#include <memory>

// g++ --version == 13.2.1
// g++ -O0 -g3 -std=gnu++20 -Wall -Wextra -Wpedantic -Werror -Wfatal-errors

class Interface
{
public:
    virtual ~Interface() noexcept = default;
};

class Implementation : public Interface
{
public:
    Implementation(int value) : value_(value) {}
    int value_ = 0;
};

class Example
{
public:
    Example(const boost::di::extension::ifactory<Interface, int>& f)
    {
        auto impl = f.create(87);
        assert(dynamic_cast<Implementation*>(impl.get()));
    }
};

namespace di = boost::di;

int main()
{
    auto injector = di::make_injector(di::bind<di::extension::ifactory<Interface, int>>().to(
        di::extension::factory<Implementation>()));
    auto example = injector.create<std::unique_ptr<Example>>();
    assert(example);
}

But this one does not compile :

#include <boost/di/extension/injections/factory.hpp>
#include <cassert>
#include <memory>

// g++ --version == 13.2.1
// g++ -O0 -g3 -std=gnu++20 -Wall -Wextra -Wpedantic -Werror -Wfatal-errors

class Interface
{
public:
    virtual ~Interface() noexcept = default;
};

class Implementation : public Interface
{
public:
    Implementation(std::shared_ptr<int> value) : value_(move(value)) {}
    std::shared_ptr<int> value_;
};

class Example
{
public:
    Example(const boost::di::extension::ifactory<Interface, std::shared_ptr<int>>& f)
    {
        auto ptr = std::make_shared<int>(87);
        auto impl = f.create(std::shared_ptr<int>(ptr));  // can i just pass `ptr` ?
        assert(dynamic_cast<Implementation*>(impl.get()));
    }
};

namespace di = boost::di;

int main()
{
    auto injector =
        di::make_injector(di::bind<di::extension::ifactory<Interface, std::shared_ptr<int>>>().to(
            di::extension::factory<Implementation>()));
    auto example = injector.create<std::unique_ptr<Example>>();
    assert(example);
}

Output is :
In file included from workdir/lib/boost/di/extension/injections/factory.hpp:11, from workdir/tests/example2.cpp:1: workdir/lib/boost/di.hpp: In instantiation of 'struct boost::ext::di::v1_3_0::aux::concept_check<boost::ext::di::v1_3_0::concepts::type_<std::shared_ptr<int> >::has_disallowed_qualifiers>': workdir/lib/boost/di.hpp:1998:9: required from 'std::unique_ptr<I> boost::ext::di::v1_3_0::extension::factory_impl<TInjector, T, boost::ext::di::v1_3_0::extension::ifactory<I, TArgs ...> >::create(TArgs&& ...) const [with TInjector = boost::ext::di::v1_3_0::core::injector<boost::ext::di::v1_3_0::config, boost::ext::di::v1_3_0::core::pool<boost::ext::di::v1_3_0::aux::type_list<> >, boost::ext::di::v1_3_0::core::dependency<boost::ext::di::v1_3_0::scopes::instance, boost::ext::di::v1_3_0::extension::ifactory<Interface, std::shared_ptr<int> >, boost::ext::di::v1_3_0::extension::factory<Implementation>, boost::ext::di::v1_3_0::no_name, void, boost::ext::di::v1_3_0::core::none> >; T = Implementation; I = Interface; TArgs = {std::shared_ptr<int>}]' workdir/lib/boost/di/extension/injections/factory.hpp:30:22: required from here workdir/lib/boost/di.hpp:379:20: error: static assertion failed: constraint not satisfied 379 | static_assert(T::value, "constraint not satisfied"); | ^~~~~ compilation terminated due to -Wfatal-errors. make[2]: *** [CMakeFiles/tu_5_framework.dir/build.make:90: CMakeFiles/tu_5_framework.dir/5_framework/tests/example2.cpp.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:485: CMakeFiles/tu_5_framework.dir/all] Error 2 make: *** [Makefile:91: all] Error 2
How to fix this code ? Thanks for your reply.

Regards,

XS

@sva522 sva522 changed the title Factory Factory with of object with shared_ptr parameter not compiling on gcc 13.2.1 and gcc 12.2.1 Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant