-
Notifications
You must be signed in to change notification settings - Fork 0
Description
N2736 is a C23 proposal that was not ultimately accepted which adds by-value lambdas (with by-value captures) whose types are un-nameable ("Voldemort types," in C++ slang).
- A copy of the proposal is here:
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2736.pdf - It is summarized here, with a summary of GCC nested functions and Clang blocks for contrast: https://thephd.dev/lambdas-nested-functions-block-expressions-oh-my
I like the proposal a lot, and it could be interesting for us to try being an early implementer when the C2y committee rolls around to re-considering it.
I think section III.1 could use an example, and a note about Copper:
It points out a parsing problem: as is, both foo and bar would parse:
int foo [[deprecated]];
int deprecated = 1;
int bar[[deprecated](){ return 1; }()];The former parses as declaring an int named foo with the deprecated attribute (added in C23) applied to it, making it a warning to use it.
Note that attribute names are identifiers, not a fixed list of keywords.
The latter parses as a variable-length array whose length is given by the immediately-invoked function expression [deprecated](){ return 1; }(), which is a call to a lambda that captures (but happens not to use) the variable deprecated, and returns 1.
This is a tragic LR conflict; N2736 estimates 20 new shift-reduce conflicts as a result. Section IV.1 suggests making a context-sensitive [[ token that goes in favor of attributes, so hey, here's something Copper's buying us. With that solution, bar would fail to parse.