Title
[tiny] Mutable is part of a lambda-declarator, so when a lambda is mutable, the parentheses aren't optional
Status
open
Section
[expr.prim.lambda]
Submitter
Herb Sutter

Created on 2014-07-02.00:00:00 last changed 122 months ago

Messages

Date: 2014-11-21.17:12:23

Proposed resolution:

Change the grammar in 5.1.2 [expr.prim.lambda] paragraph 1

lambda-expression:
      lambda-introducer lambda-declaratoropt compound-statement
...

lambda-declarator:
      ( parameter-declaration-clause ) mutableopt
            exception-specificationopt attribute-specifier-seqopt trailing-return-typeopt
      mutableopt exception-specificationopt attribute-specifier-seqopt trailing-return-typeopt

Remove from 5.1.2 [expr.prim.lambda] paragraph 4
If a lambda-expression does not include a lambda-declarator, it is as if the lambda-declarator were ().
Modify in 5.1.2 [expr.prim.lambda] paragraph 5
This function call operator or operator template is declared const (9.3.1) if and only if the lambda-expression's parameter-declaration-clause is not followed by lambda-declarator does not contain the keyword mutable.
Date: 2014-07-03.16:02:53

It has been reported that various people have noticed that it's possible to write


auto lambda = []{};

but not


auto lambda2 = [] mutable {};

In the mutable case, parentheses are required, thus:


auto lambda3 = []() mutable {};

The proposed consistency fix is to change the grammar to allow omitting the parentheses for mutable lambdas as well.

An additional question EWG needs to decide is whether the empty parentheses could be omitted for other cases besides mutable, such as


[] -> float {return 42;};
[] noexcept {foo();};

History
Date User Action Args
2014-11-21 17:12:23adminsetmessages: + msg172
2014-07-02 00:00:00admincreate