-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] errors compiling the hello world exmaple #1334
Comments
The clang version: cpp2:
cpp1:
clang error:
|
This became order-dependent after the tersest lambda change. Adding |
If it's order dependent, should cppfront still be writing out the declaration before the definition? |
Good point, not sure. I think the current error is better than simply getting a "undeclared identifier". At least it gives you a hint about what the problem might be. |
The Clang error is good, MSVC is also good:
The GCC error could use some clarification. Once you know what the error means, you can squint and see the meaning there, but it's not immediately obvious.
Without the forward declaration, the errors are:
So it's a tossup whether it's better or not. I'm guessing most C++ developers are familiar with order dependence, and know what these errors mean. Maybe cppfront can detect the order-dependent calls and produce an error? I suppose that would be difficult, since there could be another version that was |
This seems like an issue in itself. Order independence is one of the design stakes of Cpp2/cppfront - "No forward declarations or ordering gotchas." If it has turned out that this is not doable, then cppfront should accept and embrace the order-dependent nature it is forced to have, rather than pretend-having order independence, since that just ends up making issues caused by order dependence easier to stumble into and harder to figure out. If it must be order dependent, then it needs to be designed in a way that makes that clear to the programmer and as easy to deal with as possible. Currently, that is clearly not the case. |
It is not available right now for free functions with deduced return types. It's too early to say that it's not doable at all for free functions with deduced return types. Even if that were to be true, that just means that free functions with deduced return types are not order-independent. Functions with fixed return types still are. It also shouldn't affect member functions. Whether that is a large percentage of the code or not still remains to be seen. |
That is an additional complication and corner-case that one needs to be aware of and keep in mind. As far as I'm aware, one of the goals of Cpp2 was precisely to eliminate as many complications and corner-cases as is possible from Cpp1. Yes, one of those complications is order dependence itself. But if in endeavouring to eliminate it, Cpp2 merely produces a new complication ("Cpp2 is order-independent, except if/when..."), then that only does more harm than good, especially when it comes to people who are proficient in Cpp1, who are the main "target audience" anyway - it changes from being a new thing with eliminated complications w.r.t. Cpp1, to being a new thing with replaced complications w.r.t. Cpp1. And, to me, this particular complication seems worse than the one that was attempted to be resolved in the first place (order dependence). I must admit it also feels a bit like burying the head in the sand to pretend that we have yet to tell how impactful this new complication is, when the provided hello world example suffers from its consequences. If you can get caught up in a complication when writing hello world, that's plainly and simply a problem that needs to be resolved. |
Adding
hello.cpp
|
|
It is, but maybe not what you expected. Omitting { } translates to returning the expression. // these are equivalent
f: (a, b) = a + b;
f: (a, b) -> _ = { return a + b; } I for one expect and prefer that the shorter syntax returns my expression. It makes writing simple callbacks and predicates a breeze! So adding { } in the hello world example makes it return void which doesn't have any order-dependent issues. |
There is discussion of this exact thing in the notes on the last release:
|
As @zaucy described, you're not just omitting the If you have this function (things inside
then you can remove the body prefix
If the type of If that type is Depending on where this definition is, you may need to add a
|
D'oh, apologies, I knew that, but just forgot. |
Describe the bug
I get a couple of compiler errors compiling
hello.cpp
which is generated from thehello.cpp2
exampleTo Reproduce
Steps to reproduce the behavior:
cppfront
onhello.cpp2
from the documentation results inhello.cpp
#define CPP2_IMPORT_STD Yes//=== Cpp2 type declarations ====================================================
#include "cpp2util.h"
#line 1 "hello.cpp2"
//=== Cpp2 type definitions and function declarations ===========================
#line 1 "hello.cpp2"
auto main() -> int;
#line 7 "hello.cpp2"
[[nodiscard]] auto hello(cpp2::impl::instd::string_view msg) -> decltype(auto);
//=== Cpp2 function definitions =================================================
#line 1 "hello.cpp2"
auto main() -> int{
#line 2 "hello.cpp2"
std::vector words {"Alice", "Bob"};
hello(CPP2_ASSERT_IN_BOUNDS_LITERAL(words, 0));
hello(CPP2_ASSERT_IN_BOUNDS_LITERAL(cpp2::move(words), 1));
}
#line 7 "hello.cpp2"
[[nodiscard]] auto hello(cpp2::impl::instd::string_view msg) -> decltype(auto) {
return std::cout << "Hello, " + cpp2::to_string(msg) + "!\n"; }
Command lines including which C++ compiler you are using:
g++ version 14.2.0 on Ubuntu 24.4
g++ -std=c++20 hello.cpp -o hello -I$HOME/.local/cppfront/include
Expected result - compile successfully
Actual result/error:
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: