[C++] – GCC和LLVM对方法 warning: non
最近做一个C++开源项目发现一个奇怪问题,通过clang编译链接执行程序每到有一个就崩溃了,gcc下则没有此问题。
后来通过调试,发现原因是bool返回的方法是没有return语句!问题是为啥还能通过编译呢?
列子如下:
#include <iostream>
class Test {
public:
bool yes();
};
bool Test::yes() {
std::cout << "yes" << std::endl;
// return false;
};
int main() {
Test *t = new Test;
bool r = t->yes();
std::cout << "yes->" << r << std::endl;
return 0;
}

![[C++] - GCC和LLVM对方法 warning: non](https://www.zixueka.com/wp-content/uploads/2024/01/1706686271-00c9f5f300f293c.jpg)
