Thanks to visit codestin.com
Credit goes to github.com

Skip to content

di: Make AnyOperationState immovable #184

@coletrammer

Description

@coletrammer

Summary

The type-erased operation state it movable, which can cause issues if someone forgets to mark their operation state as immovable. In this case, it can be stored in the inline storage, and if anyone takes a pointer to it, it may become invalidated by moving the object.

Reproduction Steps

  1. Declare a di::AnyOperationState variable
  2. Move construct it into another variable
  3. Observe that this isn't a compilation error

Possible causes

The main reason for this problem was that the type-erased connect() function requires NRVO to stop moves. Since this isn't guaranteed by the standard, AnyOperationState has to be move-constructible.

This can be fixed by performing two-phase initialization in the connect() overload, which would then allow the type-erased operation state to be immovable. Then, we should make sure every operation state defined in the library is immovable, since receivers frequently store pointers back to them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdiRelevant to the di core library

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions