关于 VC++ 中字段初始化顺序、带符号比较和未使用变量的警告&太阳工作室
我希望针对以下 C++ 编译问题和相应的编译器启用警告:
未使用的变量 -- Sun Studio CC
示例:
void m() { int i = 10; }
有符号与无符号比较 - VC++ 和 Sun Studio CC
示例:
if ((unsigned) 10 < -1);
错误的字段初始化顺序 - VC++ 和 Sun Studio CC
示例:
class A { int i, j; A() : j(0), i(0) {} };
所有这些都被 GCC 捕获,我想在 VC++ 和 Sun Studio 中启用它们。
bash-4.1$ g++ -Wall main.cpp
main.cpp: In function ‘void m()’:
main.cpp:1: warning: comparison between signed and unsigned integer expressions
main.cpp:1: warning: unused variable ‘i’
main.cpp: In constructor ‘A::A()’:
main.cpp:1: warning: ‘A::j’ will be initialized after
main.cpp:1: warning: ‘int A::i’
main.cpp:1: warning: when initialized here
编辑: 除了在 VC++ 上启用有符号与无符号比较警告之外,所有其他选项似乎都不可行。
I am hoping to enable warnings for the following C++ compilation issues and corresponding compilers:
Unused variables -- Sun Studio CC
Example:
void m() { int i = 10; }
Signed to unsigned comparison - VC++ and Sun Studio CC
Example:
if ((unsigned) 10 < -1);
Wrong field initialization order - VC++ and Sun Studio CC
Example:
class A { int i, j; A() : j(0), i(0) {} };
All of these are caught by GCC and I would like to enable these in VC++ and Sun Studio.
bash-4.1$ g++ -Wall main.cpp
main.cpp: In function ‘void m()’:
main.cpp:1: warning: comparison between signed and unsigned integer expressions
main.cpp:1: warning: unused variable ‘i’
main.cpp: In constructor ‘A::A()’:
main.cpp:1: warning: ‘A::j’ will be initialized after
main.cpp:1: warning: ‘int A::i’
main.cpp:1: warning: when initialized here
EDIT: Outside enabling signed to unsigned comparison warnings on VC++, all other options do not seem to be possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Visual Studio、项目属性、C++ 中,将警告级别设置为 4(最大) - VC++ 编译器会给出所有可能的警告。 AFAIK,报告警告 1 和 2,并且 VC++ 编译器不报告字段初始化顺序。
In Visual Studio, Project Properties, C++, set warning level to 4 (maximum) - VC++ compiler gives all possible warnings. AFAIK, warnings 1 and 2 are reported, and field initialization order is not reported by VC++ compiler.