clang-concepts-monorepo icon indicating copy to clipboard operation
clang-concepts-monorepo copied to clipboard

Parsing: Retry as expression instead when reaching open-brace at block-scope

Open hubert-reinterpretcast opened this issue 6 years ago • 3 comments

Given:

constexpr bool q = true;
constexpr auto x = [] { return 42; };
using FTy = decltype(x);
void g(bool);

void f() {
  FTy (x)() &
  requires(bool (q)) { g(q); };
}

The { should trigger parsing of the statement as an expression-statement since, in this context, it can start neither a function-body nor an initializer.

Currently we get:

<source>:8:22: error: function definition is not allowed here
  requires(bool (q)) { g(q); };
                     ^
1 error generated.

hubert-reinterpretcast avatar Jan 18 '19 19:01 hubert-reinterpretcast

Nice catch! Is this supposed to be well-formed though? Why would a requires-expression be allowed after that &?

saarraz avatar Jan 18 '19 19:01 saarraz

Why would a requires-expression be allowed after that &?

The first part is a call that produces an int; a requires-expression is just a bool, and thus allowed there.

hubert-reinterpretcast avatar Jan 18 '19 20:01 hubert-reinterpretcast

gotcha

saarraz avatar Jan 18 '19 20:01 saarraz