error: control may reach end of non-void function [-Werror,-Wreturn-type]

时间:2023-03-09 19:32:45
error: control may reach end of non-void function [-Werror,-Wreturn-type]

编译出现如下错误

error: control may reach end of non-void function [-Werror,-Wreturn-type]

这个错误可能和编译器有关(在相同代码情况有的编译器可能不会报错,而有的可能会报错),也可能是因为函数没有返回值导致,比如:下面这个函数,如果输入参数a < b 就会导致函数没有返回值。

int fun(int a, int b){
if(a > b) return a;
}