[PATCH] D28510: Reinstate CWG1607 restrictions on lambdas appearing inside certain constant-expressions

Richard Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 23 11:56:07 PST 2017


rsmith requested changes to this revision.
rsmith added a comment.
This revision now requires changes to proceed.

I don't think it's possible to check this in the way you're doing so here. In general, there's no way to know whether a constant expression will be part of a `typedef` declaration or function declaration until you've finished parsing it (when you're parsing the decl-specifiers in a declaration you don't know whether you're declaring a function or a variable, and the `typedef` keyword might appear later).

So I think you need a different approach here. How about tracking the set of contained lambdas on the `Declarator` and `DeclSpec` objects, and diagnose from `ActOnFunctionDeclarator` / `ActOnTypedefDeclarator` if the current expression evaluation context contains any lambdas? (Maybe when entering an expression evaluation context, pass an optional `SmallVectorImpl<Expr*>*` to `Sema` to collect the lambdas contained within the expression.)

There are some particularly "fun" cases to watch out for here:

  decltype([]{})
    a, // ok
    f(); // ill-formed

... that require us to track the lambdas in the `DeclSpec` separately from the lambdas in the `Declarator`.


Repository:
  rL LLVM

https://reviews.llvm.org/D28510





More information about the cfe-commits mailing list