iceoryx icon indicating copy to clipboard operation
iceoryx copied to clipboard

Issues with function_ref

Open ymarcov opened this issue 1 year ago • 10 comments

Required information

Operating system: Any

Compiler version: Any

Eclipse iceoryx version: master

Observed result or behaviour: In cxx::function_ref:

  1. operator() is marked noexcept
  2. Construction erroneously accepts rvalue capturing lambdas (i.e. [&] { ... })
  3. Construction invokes UB when accepting rvalue non-capturing lambdas (i.e. [] { ... })

Expected result or behaviour:

  1. operator() should not be marked noexcept, since it is unreasonable for the program to terminate if the user-code invoked throws an exception.
  2. Capturing lambdas necessarily imply state, and it is a mistake that function_ref can be built with stateful rvalues. Attempting this construction should result in a compilation error.
  3. Non-capturing lambdas should be okay for construction, since they are convertible to a function pointer. However, the current implementation still saves them as objects, and applies callable_object(args...) on them where callable_object is now necessarily a dangling reference.

ymarcov avatar Feb 15 '23 07:02 ymarcov