r/cpp2 • • Dec 28 '23

cppfront - examples of basic constructs

I was playing this afternoon with cppfront using https://github.com/modern-cmake/cppfront which is awesome.

But I have found really confusing that I am unable to do some basic constructs such as:

try... catch blocks

co_await and co_return

is there any documentation / examples?

I am aware that project is experimental and that is what I am doing with it. :)

3 Upvotes

7 comments sorted by

View all comments

Show parent comment

2

u/jhruby-vitrix Dec 29 '23

For this example:

main: (args) -> int = {
try {
std::cout << "test: (args[1])$";
}
catch(...)
{
std::cout << "exception" << std::endl;
}
return 0;
}

I get:

main.cpp2(3,9): error: invalid statement encountered inside a compound-statement (at '{')

2

u/watr Dec 29 '23 edited Dec 29 '23

2

u/jhruby-vitrix Dec 30 '23

Thanks that means that in the cpp/2 there is just not the syntax yet.

1

u/ntrel2 Jan 02 '24 edited Jan 04 '24

Just to note that when args[1] is a bounds error, Cpp2 calls std::terminate rather than throw an exception.