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

Indirect binding to constructor seems not to work correctly #534

Open
mstaz opened this issue Jan 17, 2022 · 0 comments
Open

Indirect binding to constructor seems not to work correctly #534

mstaz opened this issue Jan 17, 2022 · 0 comments

Comments

@mstaz
Copy link
Contributor

mstaz commented Jan 17, 2022

Expected Behavior

The examples show a way to bind to a constructor and provide some constant value to it. This works in the simple case, but should also work in more complex cases.

Actual Behavior

When the binding to constructor is done indirectly via a binding to an interface, the constant values are not passed to the constructor anymore.

Steps to Reproduce the Problem

namespace di = boost::di;

struct interface {
  virtual ~interface() noexcept = default;
};

struct user : public interface
{
  explicit user(int value) {
      assert(value == 3);
  }
};

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

  injector.create<interface>();
}

Link to CompileExplorer
The assertion fails because value is 0. However when injector.create<user>(); is called it works just fine.
Same behavior with clang and gcc.

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