hsutter / cppfront

A personal experimental C++ Syntax 2 -> Syntax 1 compiler
Other
5.47k stars 240 forks source link

[SUGGESTION] functions/lambdas in requires #434

Open realgdman opened 1 year ago

realgdman commented 1 year ago

Not full issue, just several observations

foo: () -> bool = true; S: <T: type> type one of requires below = { }

requires foo() requires (foo())

  1. I haven't found way to write constexpr function in cpp2 which is needed here. This could be separate issue.
  2. Imagine foo is constexpr. But currently there is following cpp1 error:

    error: use of undeclared identifier 'foo' error: requires clause differs in template redeclaration

Because emitted declarations in that order:

template<typename T> requires( (foo()) ) class S //undeclared foo
auto foo() -> bool;
template<typename T> requires( (foo()) ) class S //template redeclaration
auto foo() -> bool { return true;  }

As I understand classes declared first, so we can refer them in functions, but in this case its opposite, class declaration relies on function.

  1. Immediate lambda invocation
    requires :(x)=true;(0)
    requires :(x)->_=true;(0)
    requires (:(x)->_=true;(0))

    All those give cpp2 parse error

    error: unexpected end of source file

Additional info, example of cpp1 requires with function and lambda https://godbolt.org/z/a48YePnxe

JohelEGP commented 1 year ago

See also #323, #385.