Community
cancel
Showing results for 
Search instead for 
Did you mean: 
168 Views

unexpected warning #1011: missing return statement at end of non-void function

Looks like in some cases ICC doesn't notice a noreturn attribute of the called function. Below is a simple example that illustrates the problem.
(In practice, in my program abort() is called from ASSERT() macro that does something more, but the key point is the usage of comma operator).

#include <stdlib.h>

int noret1(void) {
        abort(), 0; /* warning #1011 */
        abort(), abort(); /* warning #1011 */
}
int noret2(void) {
        abort(); /* ok - no warning */
}

int main(int argc, const char *argv[]) {
        return noret1() + noret2();
}

 

0 Kudos
5 Replies
Viet_H_Intel
Moderator
168 Views

 

You can use -Wall or -ww1011 to get the warning.

vahoang@orcsle100:/tmp$ icc t.c -c -Wall
t.c(3): warning #1011: missing return statement at end of non-void function "noret2"
  }
  ^

vahoang@orcsle100:/tmp$ icc t.c -c -ww1011
t.c(3): warning #1011: missing return statement at end of non-void function "noret2"
  }

Regards,

Viet Hoang

168 Views

Thanks for response, but I'm not sure what you mean.
The point is I don't want to see this warning, even with -Wall. There is no bug in the example code - because of abort() (which does not return) the end of the function would never be reached (which is intentional), so it doesn't matter if there is return statement or not.
gcc and clang do not throw a warning in such case. icc does, but only if comma operator is used (noret1). I suspect it to be a bug in the compiler (icc version 17.0.4).

Viet_H_Intel
Moderator
168 Views

What ICC version are you using? I dont see an error with ICC 17.0.4 version.

Thanks,

Viet Hoang

Viet_H_Intel
Moderator
168 Views

[vahoang@bec-dev3-x64 tmp]$ cat tt.c
#include <stdlib.h>

int noret1(void) {
        abort(), 0; /* warning #1011 */
        abort(), abort(); /* warning #1011 */
}

int noret2(void) {
        abort(); /* ok - no warning */
}

int main(int argc, const char *argv[]) {
        return noret1() + noret2();
}
[vahoang@bec-dev3-x64 tmp]$ icc tt.c -c
[vahoang@bec-dev3-x64 tmp]$ icc -V
Intel(R) C Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0.4.196 Build 20170411
Copyright (C) 1985-2017 Intel Corporation.  All rights reserved.

[vahoang@bec-dev3-x64 tmp]$

168 Views

[krzycz@krzycz-fedora ~]$ cat tt.c
#include <stdlib.h>

int noret1(void) {
        (void)(abort(), 0); /* this what my ASSERT() evaluates to */
}

int noret2(void) {
        abort(); /* ok - no warning */
}

int main(int argc, const char *argv[]) {
        return noret1() + noret2();
}

[krzycz@krzycz-fedora ~]$ gcc -Wall ./tt.c
[krzycz@krzycz-fedora ~]$ clang -Wall ./tt.c
[krzycz@krzycz-fedora ~]$ /opt/intel/bin/icc -Wall ./tt.c
./tt.c(5): warning #1011: missing return statement at end of non-void function "noret1"
  }
  ^

[krzycz@krzycz-fedora ~]$