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
Fix compile error for non-void-returning inplace_functions #717
Fix compile error for non-void-returning inplace_functions #717
Conversation
d8075b4
to
75d4f88
Compare
I just changed (Note: I believe |
Here's another reason for why this change is appropriate: If |
8e172b2
to
33ed570
Compare
Another few comments:
|
Looks like this would change the default behavior from no operation to stopping the user's program. |
This is how I’m not sure how else to solve the compile error without stopping the program. Did you try the example program? |
We're not adopting std::function exception behavior. The intention for callbacks on Teensy is that uninitialized callbacks are "safe" and do nothing if called anyway. Yes, this is a departure from C++ std::function convention where an exception is thrown. It is an intentional choice. |
There’s a choice here:
Edit: I was wrong about not being able to compile for void returns if there is no halt. Paul proposed a working solution below. |
Perhaps this would solve the problem?`
|
I don’t disagree with that decision, however, as of right now, the file doesn’t compile. If you don’t want to “throw”, what about calling “abort”? |
That might work, but I'm not sure about the general case. Could we at least put this inside an |
I'm reluctant to make this configurable, since it's included by Arduino.h. And as a general trend, on the forum we're seeing the most common problem transition from power-only USB cables to people using slightly different configurations or tools (which often they don't disclose until many messages digging into the problem) that cause their implementation of the core library to differ in unexpected ways. I want to enable people to experiment, but at the same time we the platform to be stable and predictable for the sake of support. |
This solution means we're returning 0 from a |
Please give |
Looks like it compiles fine for |
Must confess, I'm not a C++ template expert... but info I've been able to find says that use of static_cast can convert to void type, so we're not really returning 0 in the void case. |
From here: https://en.cppreference.com/w/cpp/language/static_cast:
I'll update this PR... |
If I understand correctly, this is not about unitialized callbacks. Actually you are checking for those in The issue is, that the current Edit: just saw that you found a solution :-) Ignore my late comment... |
The error occurs when testing for or calling an unassigned function.
33ed570
to
16b1261
Compare
I'm curious, @luni64, what would be your personal preferences for these (obviously @PaulStoffregen is the final arbiter, I was just curious about your opinions, even if they differ):
Note: I just force-pushed to make the test program compile and to keep in line with Paul's wishes. |
I'd vote for an abort/crash in whatever form, Trying to call a function through a non initialized inplace_function variable is conceptually the same as trying to call a function through a non initialized function pointer variable. The latter will cause some unpredictable behaviour. For the former we can at least generate a defined crash / crashreport. I don't see why a program should continue running if one tries to call a function with undefined adress. It would only hide a bug. |
That would be my vote too. I strongly agree with you. |
Looks like we're going to continue this conversation on #719, so I'm locking this closed issue. |
The error occurs when testing for or calling an unassigned function.
Here's a test program: