Skip to content

Align with N2736? #5

@remexre

Description

@remexre

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).

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions