Open Bug 1157788 Opened 4 years ago Updated 2 years ago

Forbid lambda default-capture modes (i.e. [=] and [&])

Categories

(Firefox Build System :: Source Code Analysis, defect)

defect
Not set

Tracking

(Not tracked)

People

(Reporter: bent.mozilla, Unassigned)

Details

Attachments

(7 files)

Using the default-capture modes for lambdas (i.e. [=] and [&]) it is very easy to accidentally capture stack variables, arguments, members, or anything that has a different lifetime than the lambda. The problem only gets worse as future hackers make changes to old lambdas since the syntax of lambdas doesn't immediately make it obvious that you're writing async code.

We should forbid default-capture modes and require explicit opt-in for the variables that we expect to be captured. That way new lambda authors will have to think twice about lifetimes, and maintainers will be alerted via compile errors that they're modifying a lambda.
I'm not sure if this is something which we necessarily want, but I had some free time, and it wasn't very hard to do. 
This prevents default capture modes and then removes all uses from the code.
Assignee: nobody → michael
Attachment #8643258 - Flags: feedback?(ehsan)
Comment on attachment 8643258 [details] [diff] [review]
Part 1: Add an analysis to forbid lambda default-capture modes

Clearing the feedback because a) I don't think we want to do this, and b) the code is definitely bitrotted by now.
Attachment #8643258 - Flags: feedback?(ehsan)
Assignee: michael → nobody
Product: Core → Firefox Build System
You need to log in before you can comment on or make changes to this bug.