Explain what you would like to see improved and how.
Running the following lines in the interpreter (line by line, not as a macro) produces an unexpected result (as in, a result that doesn't logically follow from surface knowledge of how the interpreter treats line-by-line statements + how C++ behaves):
int foo = 1
auto f = [=] { return foo; }
f()
foo = 2
f()
Expected output:
Actual output:
ROOT_prompt_1:1:1: warning: captures will be by reference, not copy
auto f = [=]{return foo;}
^
(int) 1
(int) 2
The same happens if we use explicit capture by name: auto f = [foo=foo] { return foo; }.
This is unexpected because, even knowing the variable declarations will be hoisted to the global scope, in regular C++:
- one cannot declare a global capture-default lambda; (should not compile)
- one can declare a global capture-by-named-copy lambda (
[foo=foo]) and it works as expected (captures the value, not the reference).
NOTE: running the same code as a macro works as expected.
ROOT version
master
Installation method
any
Operating system
Linux (likely any)
Additional context
No response
Explain what you would like to see improved and how.
Running the following lines in the interpreter (line by line, not as a macro) produces an unexpected result (as in, a result that doesn't logically follow from surface knowledge of how the interpreter treats line-by-line statements + how C++ behaves):
Expected output:
Actual output:
The same happens if we use explicit capture by name:
auto f = [foo=foo] { return foo; }.This is unexpected because, even knowing the variable declarations will be hoisted to the global scope, in regular C++:
[foo=foo]) and it works as expected (captures the value, not the reference).NOTE: running the same code as a macro works as expected.
ROOT version
master
Installation method
any
Operating system
Linux (likely any)
Additional context
No response