#include <stdio.h>
#include <iostream>
__attribute__((optimize("O2"))) static void* verify(char *str)
{
if (str[0] == 0)
{
puts("MM");
exit(-2);
}
}
int main(int argc,char **argv)
{
verify(argv[0]);
puts("GG");
return 1;
}
Here is my code. When I compile it using g++8/g++9/clang++-6/clang++-8
with -O2
optimization, the program prints "MM" instead of "GG". I know return statement is missing in function verify
, but I never use the return
value. Is there any explanation?
By the way, my test environment is ubuntu 1804
and g++-7
generates correct program.