[BUG] cppfront >v0.8 emit uncompilable C++ code
Describe the bug The simple hello example successfully processed by cppfront v0.7.3, but cppfront >v0.8.x emit uncompilable C++ code
To Reproduce Steps to reproduce the behavior:
- `main: () = { words: std::vector = ( "Alice", "Bob" ); hello( words[0] ); hello( words[1] ); }
hello: (msg: std::string_view) = std::cout << "Hello, (msg)$!\n";`
- Command lines including which C++ compiler you are using: cppfront hello.cpp2
- Expected result - what you expected to happen:
cppfront v0.7.3 generate:
auto hello(cpp2::impl::in<std::string_view> msg) -> void; - Actual result/error
cppfront v0.8.x generate:
[[nodiscard]] auto hello(cpp2::impl::in<std::string_view> msg) -> decltype(auto);
gcc error: error: use of ‘decltype(auto) hello(cpp2::impl::in<std::basic_string_view
Additional context
Issue can be simply fixed in cpp2 code like this:
hello: (msg: std::string_view) = { std::cout << "Hello, (msg)$!\n"; }
But this is very strange in my opinion.
After lengthy discussions here in the repo, with many people, the behavior of the tersest function syntax (no braces, no declared return type) was intentionally changed from returning void to returning the type of the statement in order to make it significantly more useful. This makes it order dependent in cpp1, and so it has to appear before it is used.
As you have discovered, by not removing the braces from the function definition, it keeps the void return type that makes it order independent.