Is there an equivalent of gcc's -Wshadow in visual C++

c++, compiler-warnings, visual-c++

Solution

I am afraid no.

You could perhaps try compiling your code with Clang:

- it has this warning (and a lot of others)

- it has a compatibility mode for MSVC headers (and can build most of MFC)

We use gcc at work, to build our code, but compile with Clang regularly to test the code conformance to the Standard and benefit from its warnings.

Problem

-Wshadow will "Warn whenever a local variable shadows another local variable.". Is there an equivalent in Visual C++ (2008)? I tried /W4 but it didn't pick up on it. I also tried Cppcheck but that didn't see it either. e.g. if I inadvertently do: ``` class A { private: int memberVar; public: void fn() { int memberVar = 27; } }; ``` I would really like to know about it!

Original source

Related problems