-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Problem with int function which doesn't return a value #8421
Comments
should be a fatal error since #8165 via Lines 24 to 28 in b5f3d1d
you should not be able to build the binary, can you check that the verbose build logs for .ino.cpp compilation actually have the flag above? |
...but, there's still an issue with the g++ arguments in 'no warnings' mode,
but I'm not sure whether we can do something about it |
First, thanks for your prompt answer.
There is indeed a problem with gcc options.
But I think there is also an issue with the generated code. As explained, when the loop was over, the function did NOT return properly and the loop resumed its execution with vale’s of loop index well above the limit. It was very strange and it was quite difficult to understand the real error (lack of return value). Once the function modified with a return value everything is working fine.
… Le 24 déc. 2021 à 13:15, Max Prokhorov ***@***.***> a écrit :
...but, there's still an issue with the g++ arguments in 'no warnings' mode, -w takes precedence over -Werror=...
$ g++ -v
...
gcc version 11.2.1 20210728 (Red Hat 11.2.1-1) (GCC)
$ g++ -w -Werror=return-type -o /dev/null no-return.cpp
$ cat no-return.cpp
int test() {
}
int main() {
test();
}
but I'm not sure whether we can do something about it
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you authored the thread.
|
Generated code is subject to the undefined behaviour, so anything could
happen at runtime :)
"Unlike in C, in C++, flowing off the end of a non-void function other than
main results in undefined behavior even when the value of the function is
not used."
https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#:~:text=Unlike%20in%20C%2C%20in%20C%2B%2B%2C%20flowing%20off%20the%20end%20of%20a%20non%2Dvoid%20function%20other%20than%20main%20results%20in%20undefined%20behavior%20even%20when%20the%20value%20of%20the%20function%20is%20not%20used
.
пт, 24 дек. 2021 г., 18:22 thierry7100 ***@***.***>:
…
First, thanks for your prompt answer.
There is indeed a problem with gcc options.
But I think there is also an issue with the generated code. As explained,
when the loop was over, the function did NOT return properly and the loop
resumed its execution with vale’s of loop index well above the limit. It
was very strange and it was quite difficult to understand the real error
(lack of return value). Once the function modified with a return value
everything is working fine.
> Le 24 déc. 2021 à 13:15, Max Prokhorov ***@***.***> a écrit :
>
>
> ...but, there's still an issue with the g++ arguments in 'no warnings'
mode, -w takes precedence over -Werror=...
>
> $ g++ -v
> ...
> gcc version 11.2.1 20210728 (Red Hat 11.2.1-1) (GCC)
> $ g++ -w -Werror=return-type -o /dev/null no-return.cpp
> $ cat no-return.cpp
> int test() {
> }
>
> int main() {
> test();
> }
> but I'm not sure whether we can do something about it
>
> —
> Reply to this email directly, view it on GitHub, or unsubscribe.
> Triage notifications on the go with GitHub Mobile for iOS or Android.
> You are receiving this because you authored the thread.
—
Reply to this email directly, view it on GitHub
<#8421 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABANG2PSH3UISLXNR2YJC3USSF3HANCNFSM5KWOYECA>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
----------------------------- Delete below -----------------------------
If your issue is a general question, starts similar to "How do I..", is related to 3rd party libs, or is related to hardware, please discuss at a community forum like esp8266.com.
INSTRUCTIONS
If you do not follow these instructions, your issue may be dismissed.
https://arduino-esp8266.readthedocs.io/en/latest/Troubleshooting/stack_dump.html
https://arduino-esp8266.readthedocs.io/en/latest/Troubleshooting/debugging.html
----------------------------- Delete above -----------------------------
Basic Infos
Platform
Settings in IDE
Problem Description
I have build a function returning an int but I forgot to return a value. This error is NOT detected by the IDE and worse the function doesn't not exist properly. In fact, the function doesn't exit and resume the loop (see below)
In the simple example provided, I got an exception, but in the complete program, nothing at all, the loop doesn't stop running after the limit was reached without error on the console.
MCVE Sketch
int TestFunction()
{
long int val = 1;
for ( int r = 0; r < 10; r++ )
{
for ( int c = 0; c < 10; c++)
{
val = val + 5;
}
}
}
void setup() {
Serial.begin(115200);
delay(500);
Serial.println("Starting and calling TestFunction");
TestFunction();
Serial.println("Done.\n");
}
void loop() {
// put your main code here, to run repeatedly:
}
Debug Messages
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4
tail 4
chksum 0xc9
csum 0xc9
v00042760
~ld
SDK:2.2.2-dev(38a443e)/Core:3.0.2=30002000/lwIP:STABLE-2_1_2_RELEASE/glue:1.2-48-g7421258/BearSSL:6105635
Starting and calling TestFunction
Fatal exception 9(LoadStoreAlignmentCause):
epc1=0x40201050, epc2=0x00000000, epc3=0x00000000, excvaddr=0x0000003b, depc=0x00000000
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
Exception (9):
epc1=0x40201050 epc2=0x00000000 epc3=0x00000000 excvaddr=0x0000003b depc=0x00000000
ctx: cont
sp: 3ffffe00 end: 3fffffc0 offset: 0190
3fffff90: 3fffdad0 00000000 3ffee568 40201050
3fffffa0: feefeffe feefeffe 3ffee5bc 40201cb4
3fffffb0: feefeffe feefeffe 3ffe85d8 40100ea9
<<<stack<<<
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
The text was updated successfully, but these errors were encountered: