You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Capturing a local variable by reference in a static lambda is a recipe for undefined behaviour:
intfoo() {
int result = 0;
staticauto lambda = [&result] {
++result;
};
lambda();
return result;
}
intmain() {
foo();
foo(); // oops, the lambda is modifying the `result` variable from the first call
}
It would be nice if clang warned about this.
(Such a bug was caught recently in the LLVM codebase itself, #109367.)
The text was updated successfully, but these errors were encountered:
Capturing a local variable by reference in a static lambda is a recipe for undefined behaviour:
It would be nice if clang warned about this.
(Such a bug was caught recently in the LLVM codebase itself, #109367.)
The text was updated successfully, but these errors were encountered: