5

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.

Nick
  • 5,765
  • 5
  • 27
  • 36

1 Answers1

2

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.

Alex F
  • 42,307
  • 41
  • 144
  • 212
  • Does anyone know if this is still the case with vc2015? Some special flag somewhere? – Mark Storer Feb 14 '17 at 16:54
  • Not yet. https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/2553854-c-compiler-should-warn-about-wrong-member-initia – EricLaw Mar 22 '17 at 21:14