Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Make-Wshadow忽略初始值设定项列表_C++_Gcc_Gcc Warning_Shadowing - Fatal编程技术网

C++ Make-Wshadow忽略初始值设定项列表

C++ Make-Wshadow忽略初始值设定项列表,c++,gcc,gcc-warning,shadowing,C++,Gcc,Gcc Warning,Shadowing,在一个大型项目中,我最近发现了一个隐藏成员变量的问题。为了避免将来出现这些问题,我想引入-Wshadow来说明这些问题。但是,大多数构造函数如下所示: struct Foo{ int bar1, bar2; Foo(int bar1, int bar2): bar1(bar1), bar2(bar2){} } 这很好也很方便,但是编译器会发出警告,所以我会在这些地方收到警告。当然,我可以更改参数名称或成员变量(但它们应该被称为什么?一个“bar1”已经完美地描述了名称…),但由于这是一

在一个大型项目中,我最近发现了一个隐藏成员变量的问题。为了避免将来出现这些问题,我想引入-Wshadow来说明这些问题。但是,大多数构造函数如下所示:

struct Foo{
  int bar1, bar2;
  Foo(int bar1, int bar2): bar1(bar1), bar2(bar2){}
}
这很好也很方便,但是编译器会发出警告,所以我会在这些地方收到警告。当然,我可以更改参数名称或成员变量(但它们应该被称为什么?一个“bar1”已经完美地描述了名称…),但由于这是一个从实际问题转移注意力的大量工作,我现在更希望gcc忽略初始值设定项列表


是否有任何标志/选项/。。。其行为类似于Wshadow,但忽略初始值设定项列表?

使用临时忽略警告

struct Foo{

  int bar1, bar2;

  #pragma GCC diagnostic push
  #pragma GCC diagnostic ignored "-Wshadow"
  Foo(int bar1, int bar2)
  :bar1{bar1}
  ,bar2{bar2}
  {}
  #pragma GCC diagnostic pop

};