boost-ext / di

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

Doesn't compile with msvc 2019 #440

Closed Manulan27 closed 4 years ago

Manulan27 commented 4 years ago

Expected Behavior

Compiling as usual.

Actual Behavior

After upgrading my project from msvc 2017 to msvc 2019 boost di doesn't compile anymore. Even creating a basic example as shown below doesn't work anymore.

Steps to Reproduce the Problem

Use msvc 2019 and any of the language standard settings (default, c++14, c++17, c++latest)

#include <boost/di.hpp>
class Foo
{   
};
int main(int argc, char* argv[])
{
    auto injector = boost::di::make_injector();
    injector.create<Foo>();
    return 0;
}

the error:

boost\di.hpp(2955,18): error C2440: 'static_cast': cannot convert from 'TDefault' to 'boost::di::v1_1_0::core::dependency &' boost\di.hpp(2955,18): error C2440: with boost\di.hpp(2955,18): error C2440: [ boost\di.hpp(2955,18): error C2440: TDefault=boost::di::v1_1_0::core::dependency<boost::di::v1_1_0::scopes::deduce,Foo,Foo,boost::di::v1_1_0::no_name,void,boost::di::v1_1_0::core::none> boost\di.hpp(2955,18): error C2440: ] boost\di.hpp(2955,18): message : static_cast and safe_cast to reference can only be used for valid initializations or for lvalue casts between related classes boost\di.hpp(2879): 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<>>>::create_successful_impl__<TIsRoot,T,boost::di::v1_1_0::no_name>(void) const' being compiled boost\di.hpp(2879): message : with boost\di.hpp(2879): message : [ boost\di.hpp(2879): message : TConfig=boost::di::v1_1_0::config, boost\di.hpp(2879): message : TIsRoot=boost::di::v1_1_0::aux::true_type, boost\di.hpp(2879): message : T=Foo boost\di.hpp(2879): message : ] boost\di.hpp(2772): 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<>>>::create_successful_impl<boost::di::v1_1_0::aux::true_type,T>(const boost::di::v1_1_0::aux::type &) const' being compiled boost\di.hpp(2772): message : with boost\di.hpp(2772): message : [ boost\di.hpp(2772): message : TConfig=boost::di::v1_1_0::config, boost\di.hpp(2772): message : T=Foo boost\di.hpp(2772): message : ] main.cpp(10): 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<>>>::create<Foo,0>(void) const' being compiled main.cpp(10): message : with main.cpp(10): message : [ main.cpp(10): message : T=Foo, main.cpp(10): message : TConfig=boost::di::v1_1_0::config main.cpp(10): message : ] main.cpp(10): 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<>>>::create<Foo,0>(void) const' being compiled main.cpp(10): message : with main.cpp(10): message : [ main.cpp(10): message : T=Foo, main.cpp(10): message : TConfig=boost::di::v1_1_0::config main.cpp(10): message : ] boost\di.hpp(2955,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.hpp(2955,107): error C2027: with boost\di.hpp(2955,107): error C2027: [ boost\di.hpp(2955,107): error C2027: TConfig=boost::di::v1_1_0::config boost\di.hpp(2955,107): error C2027: ] boost\di.hpp(2953): 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.hpp(2953): message : with boost\di.hpp(2953): message : [ boost\di.hpp(2953): message : TConfig=boost::di::v1_1_0::config boost\di.hpp(2953): message : ] boost\di.hpp(2958,9): error C2440: 'static_cast': cannot convert from 'TDefault' to 'boost::di::v1_1_0::core::dependency &' boost\di.hpp(2958,9): error C2440: with boost\di.hpp(2958,9): error C2440: [ boost\di.hpp(2958,9): error C2440: TDefault=boost::di::v1_1_0::core::dependency<boost::di::v1_1_0::scopes::deduce,Foo,Foo,boost::di::v1_1_0::no_name,void,boost::di::v1_1_0::core::none> boost\di.hpp(2958,9): error C2440: ] boost\di.hpp(2958,9): message : static_cast and safe_cast to reference can only be used for valid initializations or for lvalue casts between related classes boost\di.hpp(2958,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.hpp(2958,13): error C2027: with boost\di.hpp(2958,13): error C2027: [ boost\di.hpp(2958,13): error C2027: TConfig=boost::di::v1_1_0::config boost\di.hpp(2958,13): error C2027: ] boost\di.hpp(2953): 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.hpp(2953): message : with boost\di.hpp(2953): message : [ boost\di.hpp(2953): message : TConfig=boost::di::v1_1_0::config boost\di.hpp(2953): message : ] boost\di.hpp(2948): error C2641: cannot deduce template arguments for 'boost::di::v1_1_0::core::successful::wrapper' boost\di.hpp(2948,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' boost\di.hpp(2455): message : see declaration of 'boost::di::v1_1_0::core::successful::wrapper' boost\di.hpp(2948,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' boost\di.hpp(2455): message : see declaration of 'boost::di::v1_1_0::core::successful::wrapper' boost\di.hpp(2957,2): error C2512: 'boost::di::v1_1_0::core::successful::wrapper': no appropriate default constructor available boost\di.hpp(2957,2): message : The target type has no constructors boost\di.hpp(2773,12): error C2440: 'type cast': cannot convert from 'void' to 'T &&' boost\di.hpp(2773,12): error C2440: with boost\di.hpp(2773,12): error C2440: [ boost\di.hpp(2773,12): error C2440: T=Foo boost\di.hpp(2773,12): error C2440: ] boost\di.hpp(2773,12): message : Expressions of type void cannot be converted to other types

Specifications

krzysztof-jusiak commented 4 years ago

Thanks, @Manulan27 for reporting that.

It seems to work with msvc 19.22 -> https://godbolt.org/z/9TyvRq Unfortunately, compiler explorer doesn't have any newer version :thinking: Any ideas how to easily test it? I don't have Windows available ATM :(

kanstantsin-chernik commented 4 years ago

I am going to test it tomorrow. Not sure that I will be able to resolve it though.

krzysztof-jusiak commented 4 years ago

Thanks @kanstantsin-chernik

It might be that msvc 19.23 fixed some of the wknds we have :thinking:

#define __BOOST_DI_TYPE_WKND(T) (T &&)
#define __BOOST_DI_ACCESS_WKND public
#define __BOOST_DI_VARIABLE_TEMPLATE_INIT_WKND
Manulan27 commented 4 years ago

@krzysztof-jusiak I'm not sure about 19.22, but I'm currently using 19.23.28105.4 which is probably the latest version.

kanstantsin-chernik commented 4 years ago

@krzysztof-jusiak I tested it on 19.23. It is not a problem fro /c++14 however I got the same error with /c++17. Workarounds don't really help.

BTW, in terms of way to test it you can create Azure account. MS gives 200$ bonus. Than you can instantiate a VM with VS (it might be already in there market).

I will try to find a solution on my own. But unfortunately it is not so obvious for me.

kanstantsin-chernik commented 4 years ago

Problems: 1) It doesn't like upcasting to dependency__. But it is fixable with reinterpret_cast 2) It incorrectly deduce provider:

template <class, class>
struct provider;
kanstantsin-chernik commented 4 years ago

@Manulan27 could you please test a PR

Manulan27 commented 4 years ago

@kanstantsin-chernik I just tested your PR and the example + my project are compiling again. Thanks a lot for the fast help!

kanstantsin-chernik commented 4 years ago

You are welcome!