#include <functional>
#include <stdio.h>
void run(int v)
{
printf("%d\n", v);
}
int main()
{
int v = 5;
auto f = std::bind(run, std::ref(v));
f();
v = 10;
f();
}
The printf in run is just to "prove" that the second store is used.
1 warning generated.
/home/jack/ref.cpp:15:4: warning: Value stored to 'v' is never read [clang-analyzer-deadcode.DeadStores]
v = 10;
^ ~~
/home/jack/ref.cpp:15:4: note: Value stored to 'v' is never read
v = 10;
^ ~~
The
printf
inrun
is just to "prove" that the second store is used.