Compile error : no return statement in function returning non-void [-Werror=return-type]

Hello, I know that the project is a little old but I encountered an error that I do not understand during compilation, below are the errors encountered with the project in v0.7 .

Project Jarolift_MQTT

D:\PATH\TO\Jarolift_MQTT-0.7-2\Jarolift_MQTT-0.7\Jarolift_MQTT\Jarolift_MQTT.ino: In function 'int keeloq()':
D:\PATH\TO\Jarolift_MQTT-0.7-2\Jarolift_MQTT-0.7\Jarolift_MQTT\Jarolift_MQTT.ino:453:1: error: no return statement in function returning non-void [-Werror=return-type]
453 | } // int keeloq
| ^
D:\PATH\TO\Jarolift_MQTT-0.7-2\Jarolift_MQTT-0.7\Jarolift_MQTT\Jarolift_MQTT.ino: In function 'int keygen()':
D:\PATH\TOs\Jarolift_MQTT-0.7-2\Jarolift_MQTT-0.7\Jarolift_MQTT\Jarolift_MQTT.ino:479:1: error: no return statement in function returning non-void [-Werror=return-type]
479 | } // int keygen
| ^
D:\PATH\TO\Jarolift_MQTT-0.7-2\Jarolift_MQTT-0.7\Jarolift_MQTT\Jarolift_MQTT.ino: In function 'int rx_keygen()':
D:\PATH\TO\Jarolift_MQTT-0.7-2\Jarolift_MQTT-0.7\Jarolift_MQTT\Jarolift_MQTT.ino:641:1: error: no return statement in function returning non-void [-Werror=return-type]
641 | } // int rx_keygen
| ^
D:\PATH\TO\Jarolift_MQTT-0.7-2\Jarolift_MQTT-0.7\Jarolift_MQTT\Jarolift_MQTT.ino: In function 'int rx_decoder()':
D:\PATH\TO\Jarolift_MQTT-0.7-2\Jarolift_MQTT-0.7\Jarolift_MQTT\Jarolift_MQTT.ino:654:1: error: no return statement in function returning non-void [-Werror=return-type]
654 | } // int rx_decoder
| ^
cc1plus.exe: some warnings being treated as errors

exit status 1

Compilation error: no return statement in function returning non-void [-Werror=return-type]

Welcome to the forum

From the error messages it appears that you have functions t0aht are expected to return a value but they do not

These would normally be reported as warnings rather than errors but note the message

cc1plus.exe: some warnings being treated as errors

Which Arduino board are you using and which version of the board files do you have installed ?

1 Like

Your code does not seem to match the code in the link that you did provide.
I strongly suspect that your code has e.g.

int keeloq () {
...
...
}

but the code in the link has

void keeloq () {
...
...
}

So you might be using an older version of that code or you have been modifying it.

@UKHeliBob, these errors are typical for the ESP family :smiley:
@blastmun , in future please provide those details.

I know, hence my question as to which board is being used.

I have had to fix the unused variable warning being treated as an error "feature" many times when updating the ESP32 board files but the latest did not need fixing. Hence my question as to which board version was being used

Hi,
Thank you for your answers, it's for a wemos D1 mini (esp32).

Which version of the board files are you using ?

I downloaded the zip in 0.7 but the "master" version is different! I'm going to try this last one! THANKS

But this is a missing return statement. I would fix that one. I wouldn't be satisfied to treat it as a warning.

I realise that, but it is a moot point as to whether it should be regarded as an error or a warning

I have the Espressif version 2.0.15 installed and this behaves as follows

This compiles and runs as expected

void setup()
{
    Serial.begin(115200);
    test();
}

void loop()
{
}

bool test()
{
    Serial.println("test");
    return true;
}

Whereas this compiles

void setup()
{
    Serial.begin(115200);
    test();
}

void loop()
{
}

bool test()
{
    Serial.println("test");
}

with the following warning

C:\Users\Bob2\AppData\Local\Temp\.arduinoIDE-unsaved2024323-2904-gxlna6.6djjj\sketch_apr23b\sketch_apr23b.ino: In function 'bool test()':
C:\Users\Bob2\AppData\Local\Temp\.arduinoIDE-unsaved2024323-2904-gxlna6.6djjj\sketch_apr23b\sketch_apr23b.ino:14:1: warning: no return statement in function returning non-void [-Wreturn-type]

but the sketch causes the board to boot loop.

Setting the return type of the function to void makes the sketch behave as expected

My conclusion is that the situation is not as clear cut as it could be

What's missing? The program didn't run correctly and the compiler told you exactly where you messed up.

If the code is likely to cause a reboot, as opposed to just not doing what is required, then I would call that an error and prevent the program running

As it is you get a warning and a reboot

Q: When is a warning not a warning ?
A: When it is an error

Wasn't there a specific step you took to tell it to stop treating that warning as an error?

Maybe there was a reason for that.

Much more interesting than arguing about the classification of the error (warning), is the reason for it. As @blastmun already pointed out, the latest and greatest version of the GitHub code is different than Release v0.7 (that was originally tested).

Rev v0.7 has this ... which is clearly the problem:

//####################################################################
// Generation of the encrypted message (Hopcode)
//####################################################################
int keeloq () {
  Keeloq k(device_key_msb, device_key_lsb);
  unsigned int result = (disc << 16) | devcnt;  // Append counter value to discrimination value
  dec = k.encrypt(result);
} // int keeloq

It has since been changed to:

//####################################################################
// Generation of the encrypted message (Hopcode)
//####################################################################
void keeloq () {
  Keeloq k(device_key_msb, device_key_lsb);
  unsigned int result = (disc << 16) | devcnt;  // Append counter value to discrimination value
  dec = k.encrypt(result);
} // void keeloq

Maybe, but when unused variables were regarded as errors it was a nonsense. Easy to put right in your own code but it also caused problems with some libraries. Thankfully that seems to have been changed so that unused variables are now warnings, although I assume that the compiler removes the declaration/definition anyway

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.