[Development] Proposing changes to https://wiki.qt.io/Qt_Coding_Style
Jaroslaw Kobus
Jaroslaw.Kobus at qt.io
Tue May 9 09:20:16 CEST 2023
> - drop the requirement for () in lambdas
>
> Rationale: this was a word-around for older MSVCs. The standard doesn't
> require the empty parameter list (except when adorning the lambda with
> noexcept etc, and then the compiler complains) and people have voted
> with their feet: we now have many uses of [] {} in Qt already.
I support it and we have such a rule in QtC already. However, please note that when you specify the return type of
the lambda or define it mutable, the compiler issues the following warnings currently:
int bla = 0;
const auto foo = [] -> int { return 0; };
const auto bar = [bla] mutable { bla = 4; return 0; };
warning: parameter declaration before lambda trailing return type only optional with ‘-std=c++2b’ or ‘-std=gnu++2b’
72 | const auto foo = [] -> int { return 0; };
| ^~
warning: parameter declaration before lambda declaration specifiers only optional with ‘-std=c++2b’ or ‘-std=gnu++2b’
73 | const auto bar = [bla] mutable { bla = 4; return 0; };
| ^~~~~~~
When you add empty (), the compiler is silent.
Jarek
More information about the Development
mailing list