boost-ext / di

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

Binding to LValue Reference becomes dangling #553

Open gotschmarcel-ni opened 1 year ago

gotschmarcel-ni commented 1 year ago

Expected Behavior

Binding an lvalue reference shouldn't cause a dangling reference.

Maybe I'm misunderstanding the library design here and it's expected that bound objects have a longer lifetime than the injector. It's definitely very easy to run into this problem. If I move the object into the binding the ownership is moved to the injector and everything is fine. I'm wondering if there's a way to make this problem more obvious or less easy to run into it.

Actual Behavior

Reference to object is dangling.

Steps to Reproduce the Problem

Open the godbolt playground: https://godbolt.org/z/E5v4bhsE4

Specifications