boost-ext / di

C++14 Dependency Injection Library
https://boost-ext.github.io/di
1.16k stars 140 forks source link

Compilation errors with MSVC 2019 with c++17 option enabled #468

Open vtabota opened 4 years ago

vtabota commented 4 years ago

Expected Behavior

Expected to compile with c++17 enabled

Actual Behavior

Requires c++14 set

Steps to Reproduce the Problem

New C++ console project Project properties, C/C++, Language, Advanced, Set ISO C++ 17

Source file

#include <boost/di.hpp>
#include <cassert>
#include <memory>

namespace di = boost::di;
struct interface {
    virtual ~interface() noexcept = default;
    virtual int get() const = 0;
};

class implementation : public interface {
public:
    int get() const override { return 42; }
};

struct example {
    example(std::shared_ptr<interface> i) {
        assert(42 == i->get());
    }
};

int main() {
    const auto injector = di::make_injector(
        di::bind<interface>.to<implementation>()
    );

    injector.create<std::unique_ptr<example>>();
}

Compilation output

1>------ Build started: Project: BoostDI, Configuration: Debug x64 ------ 1>Clean.cpp 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2944,18): error C2440: 'static_cast': cannot convert from 'TDefault' to 'boost::di::v1_1_0::core::dependency &' 1> with 1> [ 1> TDefault=boost::di::v1_1_0::core::dependency<boost::di::v1_1_0::scopes::deduce,example,example,boost::di::v1_1_0::no_name,void,boost::di::v1_1_0::core::none> 1> ] 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2944,18): message : static_cast and safe_cast to reference can only be used for valid initializations or for lvalue casts between related classes 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2868): message : see reference to function template instantiation 'auto boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,boost::di::v1_1_0::core::dependency<TScope,TExpected,T,TName,TPriority,TCtor>>::create_successful_impl__<TIsRoot,std::unique_ptr<example,std::default_delete>,boost::di::v1_1_0::no_name>(void) const' being compiled 1> with 1> [ 1> TConfig=boost::di::v1_1_0::config, 1> TScope=boost::di::v1_1_0::scopes::deduce, 1> TExpected=interface, 1> T=implementation, 1> TName=boost::di::v1_1_0::no_name, 1> TPriority=void, 1> TCtor=boost::di::v1_1_0::core::none, 1> TIsRoot=boost::di::v1_1_0::aux::true_type 1> ] 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2761): message : see reference to function template instantiation 'auto boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,boost::di::v1_1_0::core::dependency<TScope,TExpected,T,TName,TPriority,TCtor>>::create_successful_impl<boost::di::v1_1_0::aux::true_type,std::unique_ptr<example,std::default_delete>>(const boost::di::v1_1_0::aux::type<std::unique_ptr<example,std::default_delete>> &) const' being compiled 1> with 1> [ 1> TConfig=boost::di::v1_1_0::config, 1> TScope=boost::di::v1_1_0::scopes::deduce, 1> TExpected=interface, 1> T=implementation, 1> TName=boost::di::v1_1_0::no_name, 1> TPriority=void, 1> TCtor=boost::di::v1_1_0::core::none 1> ] 1>C:\p4\tmp\BoostDI\BoostDI\Clean.cpp(27): message : see reference to function template instantiation 'T boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,boost::di::v1_1_0::core::dependency<TScope,TExpected,implementation,TName,TPriority,TCtor>>::create<std::unique_ptr<example,std::default_delete>,0>(void) const' being compiled 1> with 1> [ 1> T=std::unique_ptr<example,std::default_delete>, 1> TConfig=boost::di::v1_1_0::config, 1> TScope=boost::di::v1_1_0::scopes::deduce, 1> TExpected=interface, 1> TName=boost::di::v1_1_0::no_name, 1> TPriority=void, 1> TCtor=boost::di::v1_1_0::core::none 1> ] 1>C:\p4\tmp\BoostDI\BoostDI\Clean.cpp(27): message : see reference to function template instantiation 'T boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,boost::di::v1_1_0::core::dependency<TScope,TExpected,implementation,TName,TPriority,TCtor>>::create<std::unique_ptr<example,std::default_delete>,0>(void) const' being compiled 1> with 1> [ 1> T=std::unique_ptr<example,std::default_delete>, 1> TConfig=boost::di::v1_1_0::config, 1> TScope=boost::di::v1_1_0::scopes::deduce, 1> TExpected=interface, 1> TName=boost::di::v1_1_0::no_name, 1> TPriority=void, 1> TCtor=boost::di::v1_1_0::core::none 1> ] 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2944,107): error C2027: use of undefined type 'boost::di::v1_1_0::core::successful::provider<ctor_t,boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,boost::di::v1_1_0::core::dependency<TScope,TExpected,T,TName,TPriority,TCtor>>>' 1> with 1> [ 1> TConfig=boost::di::v1_1_0::config, 1> TScope=boost::di::v1_1_0::scopes::deduce, 1> TExpected=interface, 1> T=implementation, 1> TName=boost::di::v1_1_0::no_name, 1> TPriority=void, 1> TCtor=boost::di::v1_1_0::core::none 1> ] 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2942): message : see declaration of 'boost::di::v1_1_0::core::successful::provider<ctor_t,boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,boost::di::v1_1_0::core::dependency<TScope,TExpected,T,TName,TPriority,TCtor>>>' 1> with 1> [ 1> TConfig=boost::di::v1_1_0::config, 1> TScope=boost::di::v1_1_0::scopes::deduce, 1> TExpected=interface, 1> T=implementation, 1> TName=boost::di::v1_1_0::no_name, 1> TPriority=void, 1> TCtor=boost::di::v1_1_0::core::none 1> ] 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2947,9): error C2440: 'static_cast': cannot convert from 'TDefault' to 'boost::di::v1_1_0::core::dependency &' 1> with 1> [ 1> TDefault=boost::di::v1_1_0::core::dependency<boost::di::v1_1_0::scopes::deduce,example,example,boost::di::v1_1_0::no_name,void,boost::di::v1_1_0::core::none> 1> ] 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2947,9): message : static_cast and safe_cast to reference can only be used for valid initializations or for lvalue casts between related classes 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2947,13): error C2027: use of undefined type 'boost::di::v1_1_0::core::successful::provider<ctor_t,boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,boost::di::v1_1_0::core::dependency<TScope,TExpected,T,TName,TPriority,TCtor>>>' 1> with 1> [ 1> TConfig=boost::di::v1_1_0::config, 1> TScope=boost::di::v1_1_0::scopes::deduce, 1> TExpected=interface, 1> T=implementation, 1> TName=boost::di::v1_1_0::no_name, 1> TPriority=void, 1> TCtor=boost::di::v1_1_0::core::none 1> ] 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2942): message : see declaration of 'boost::di::v1_1_0::core::successful::provider<ctor_t,boost::di::v1_1_0::core::injector<TConfig,boost::di::v1_1_0::core::pool<boost::di::v1_1_0::aux::type_list<>>,boost::di::v1_1_0::core::dependency<TScope,TExpected,T,TName,TPriority,TCtor>>>' 1> with 1> [ 1> TConfig=boost::di::v1_1_0::config, 1> TScope=boost::di::v1_1_0::scopes::deduce, 1> TExpected=interface, 1> T=implementation, 1> TName=boost::di::v1_1_0::no_name, 1> TPriority=void, 1> TCtor=boost::di::v1_1_0::core::none 1> ] 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2937): error C2641: cannot deduce template arguments for 'boost::di::v1_1_0::core::successful::wrapper' 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2937,1): error C2783: 'boost::di::v1_1_0::core::successful::wrapper<T,TWrapper> boost::di::v1_1_0::core::successful::wrapper(void)': could not deduce template argument for 'T' 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2444): message : see declaration of 'boost::di::v1_1_0::core::successful::wrapper' 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2937,1): error C2783: 'boost::di::v1_1_0::core::successful::wrapper<T,TWrapper> boost::di::v1_1_0::core::successful::wrapper(void)': could not deduce template argument for 'TWrapper' 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2444): message : see declaration of 'boost::di::v1_1_0::core::successful::wrapper' 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2946,2): error C2512: 'boost::di::v1_1_0::core::successful::wrapper': no appropriate default constructor available 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2946,2): message : The target type has no constructors 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2946,24): error C2064: term does not evaluate to a function taking 1 arguments 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2762,12): error C2440: 'type cast': cannot convert from 'void' to 'T &&' 1> with 1> [ 1> T=std::unique_ptr<example,std::default_delete> 1> ] 1>C:\Users...\source\repos\vcpkg\installed\x64-windows\include\boost\di.hpp(2762,12): message : Expressions of type void cannot be converted to other types 1>Done building project "BoostDI.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Specifications

MSVC2019 16.5.5 Windows 10 Debug/x64

AlexDovgan commented 4 years ago

The same