-
Notifications
You must be signed in to change notification settings - Fork 140
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
multiple bindings broken with C++17 (VS 15.8) #350
Comments
How does your example constructor look like? Do you use std::move to move the parameter to the class variable? EDIT: @scottmcnab forget about the question above. I can confirm kind of this behavior with similar code as yours (with latest di.hpp from master branch), except that I also get the infamous "creatable constraint not satisfied" error.
I can confirm that this code works fine with MSVC 14.15 (from VS 15.8) when using /std:c++14 but not with /std:c++17. With MSVC 14.14 (from VS 15.7) this works in all cases. So there is some incompatibility with MSVC 14.15 when using C++17. |
Yes @Stannieman I have seen a similar error before with std::unique_ptr and std::vector, when the std::unique_ptr is copied into a vector. This happens because unique_ptr can only be moved, not copied. std::shared_ptr does not have this issue, because it is safe to copy/assign a shared_ptr (it just temporarily increments the reference count). The fact that this code works fine with /std:c++14 (and also with /std:c++17 in earlier Visual Studio 15.5 version compiler), suggests that for some reason the compiler is now choosing the wrong operator (eg. it selects copy assignment instead of move assignment), probably when it is constructing the std::vector<> of dependencies. Unfortunately, I am not familiar with the internals of boost-di to know where to start investigating this, let alone what kind of syntactic tweaking would be required to convince the compiler to do the right thing! If anyone could provide further insight here it would be most appreciated! |
I've opened an issue here also because at this point it's unclear if it's an issue with boost expecting non-standard behavior from the compiler, or if it's the new MSVC that's handling this case in a non-standard way. |
Something is fixed and will be in next MSVC release, not sure which problem though but I think the creatable constraint not satisfied. |
For those who are waiting for VS update, A WORKAROUND: Replace: In |
@marsermd thank you for the workaround. I am working on the update. The only |
Expected Behavior
With Visual Studio 15.8.3 and /std:c++17 compiler flag defined, multiple bindings fails to compile. i.e.
code of the form:
auto injector = di::make_injector( di::bind<interface* []>().to<implementation1, implementation2>>() );
Which used to be able to be injected using:
struct example { example(std::vector<std::unique_ptr<interface>> v) {
This same code used to compile successfully on VS 15.5 with /std:c++17 flag set.
Actual Behavior
Steps to Reproduce the Problem
C:\git\boost-di\example>cl multiple_bindings.cpp -I../include/ /EHsc /std:c++17
Specifications
Any idea how to fix this? Thanks!
The text was updated successfully, but these errors were encountered: