为什么#pragma clang诊断警告不适用于-Wunreachable-code-return?

时间:2019-09-08 21:53:36

标签: clang compiler-warnings clang++

考虑以下代码:

#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.

为什么有区别?

0 个答案:

没有答案