在视觉C ++中有相当于gcc的-Wshadow [英] Is there an equivalent of gcc's -Wshadow in visual C++

查看:1155
本文介绍了在视觉C ++中有相当于gcc的-Wshadow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

-Wshadow 会当局部变量影射另一个局部变量时发出警告。 。在Visual C ++(2008)有一个等价物?我尝试/ W4但它没有拾起它。我也尝试过 Cppcheck ,但也没有看到它。



例如如果我不经意地做:

  class A 
{
private:
int memberVar;
public:
void fn()
{
int memberVar = 27;
}
};

我真的很想知道!



您可以尝试用Clang编译您的代码:




  • 它有此警告(和许多其他人)

  • 它具有MSVC头的兼容性模式的MFC)



我们在工作中使用gcc来构建我们的代码,但是定期编译Clang来测试代码是否符合标准并受益于其警告。


-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!

解决方案

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.

这篇关于在视觉C ++中有相当于gcc的-Wshadow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆