3 ms·
``` for (auto& x : f().things()) { // dangling reference! mutate(&x); } ``` Oh shit I think I have to go through a dozen projects in production and fix som
by inetknght 9y ago
```
for (auto& x : f().things()) { // dangling reference!
mutate(&x);
}
```
Oh shit I think I have to go through a dozen projects in production and fix some code now. Thanks Herb.
- nikbackm 9y agoAre you sure? If f() returns a value then you have a problem and should fix it, but if f() instead returns a reference (that is not dangling in itself), then it should be fine.
- inetknght 9y agoclick Now it all makes sense. This is what I get for trying to read technical stuff while drunk at midnight.
- mhogomchungu 9y agoThis discussion[1] maybe useful in solving the problem. "things()" member function should be qualified with a reference to prevent it from being called from an rvalue object. [1] https://stackoverflow.com/questions/21861148/what-does-the-single-ampersand-mean-here https://stackoverflow.com/questions/21861148/what-does-the-s...