考虑以下代码:
#pragma clang diagnostic warning "-Weverything"
int main() { long x = 0; if (0) { return 1; } return x; }
如果我正常编译,我会得到:
$ clang++ -fsyntax-only temp.cpp
temp.cpp:2:54: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
int main() { long x = 0; if (0) { return 1; } return x; }
~~~~~~ ^
1 warning generated.
如果我使用-Weverything
进行编译,则会得到:
$ clang++ -fsyntax-only -Weverything temp.cpp
temp.cpp:2:54: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
int main() { long x = 0; if (0) { return 1; } return x; }
~~~~~~ ^
temp.cpp:2:42: warning: 'return' will never be executed [-Wunreachable-code-return]
int main() { long x = 0; if (0) { return 1; } return x; }
^
2 warnings generated.
为什么有区别?