Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning on field init order, signed comparison, and unused vars in VC++ & Sun Studio

I am hoping to enable warnings for the following C++ compilation issues and corresponding compilers:

  1. Unused variables -- Sun Studio CC

    Example: void m() { int i = 10; }

  2. Signed to unsigned comparison - VC++ and Sun Studio CC

    Example: if ((unsigned) 10 < -1);

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

like image 288
Nick Avatar asked Nov 04 '22 19:11

Nick


1 Answers

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.

like image 79
Alex F Avatar answered Nov 12 '22 19:11

Alex F