hsutter / cppfront

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

[BUG] Allow `static_assert` at file scope when cppfront runs in Pure Cpp2 mode #1075

Open bluetarpmedia opened 1 month ago

bluetarpmedia commented 1 month ago

(This might be more of a suggestion than a bug.)

Describe the bug Cannot use static_assert at file scope when cppfront runs in Pure Cpp2 mode.

To Reproduce Run cppfront on this code:

verify: (func, arg) -> bool == {
    return func(arg);
}

static_assert( verify(:(i: int) i < 10, 5) );  // Does not compile

main: () -> int = {

    static_assert( verify(:(i: int) i < 10, 5) );  // OK

    return 0;
}

The static_assert line at file scope does not compile because cppfront interprets it as C++ rather than Cpp2. But when cppfront runs in pure mode, the static_assert could be interpreted as being a Cpp2 statement.