On Mon, 2 Mar 2020 at 03:55, leon zadorin <leonleon77@xxxxxxxxx> wrote: > > On Mon, Mar 2, 2020 at 1:57 PM leon zadorin <leonleon77@xxxxxxxxx> wrote: > > > > template<typename T> > > void foo(T const f) > > { > > f(); > > } > ... > > the effect of 'mutable' (i.e. making operator()() non-const) are not > detected by GCC/clang to a point where both of the following compile ok: > > int main() > > { > > foo([](){}); > > foo([]() mutable {}); > > } > > > > ... actually never mind, I take it back :) I think GCC/clang are ok in > that regard, reading https://en.cppreference.com/w/cpp/language/lambda > "mutable: allows body to modify the parameters captured by copy, and to > call their non-const member functions" > > makes it more clear for me... as in the above lambdas have no captures > anyways (i.e. no effect), and with any captures (e.g. mutating with > mutable) the expected compilation failure becomes evident, so in effect > GCC/clang are doing this fine :) What they're doing seems kinda OK, but I think it's not actually allowed by the standard. The wording does say that unless the lambda uses the mutable keyword, the function call operator is const-qualified. So I think this is a bug.