saarraz / clang-concepts-monorepo

****** OBSOLETE - CONCEPTS HAS BEEN MERGED INTO CLANG TRUNK AND DEVELOPMENT CONTINUES THERE ****** This fork of llvm-project contains my implementation of C++2a Concepts for the Clang compiler, and will be updated regularly with bug fixes until the whole feature is merged to trunk. Follow the instructions here https://clang.llvm.org/get_started.html to build, then use the flags "-std=c++2a -Xclang -fconcepts-ts" to enable concepts.
27 stars 3 forks source link

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

Open hubert-reinterpretcast opened 5 years ago

hubert-reinterpretcast commented 5 years ago

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.
saarraz commented 5 years ago

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

hubert-reinterpretcast commented 5 years ago

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.

saarraz commented 5 years ago

gotcha