Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.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++ C++;带-Wshadow警告的结构化绑定?_C++_Gcc Warning_Stdtuple - Fatal编程技术网

C++ C++;带-Wshadow警告的结构化绑定?

C++ C++;带-Wshadow警告的结构化绑定?,c++,gcc-warning,stdtuple,C++,Gcc Warning,Stdtuple,更新:gcc可以工作,但不能发出叮当声 用C++17编译 GCC/Clang-Wshadow将在出现阴影局部变量时发出警告,但对于结构化绑定,此标志不起作用。如何在这种情况下暴露警告 std::tuple<int, int> yy = {-1, -2}; int x = 1; { // int x = 2; // will warn -Wshadow auto [x, y] = yy; // will not warn even if compile with

更新:gcc可以工作,但不能发出叮当声


用C++17编译

GCC/Clang-Wshadow将在出现阴影局部变量时发出警告,但对于结构化绑定,此标志不起作用。如何在这种情况下暴露警告

std::tuple<int, int> yy = {-1, -2};
int x = 1;
{
  //    int x = 2;   // will warn -Wshadow
  auto [x, y] = yy;  // will not warn even if compile with -weverything 
}
std::tuple yy={-1,-2};
int x=1;
{
//int x=2;//将发出警告-Wshadow
auto[x,y]=yy;//即使使用-weverything编译,也不会发出警告
}

我已经用gcc 9.2和clang 9.0.0试用了您的示例。这是我的最小程序:

#包括
std::tuple yy={-1,-2};
无效bla(int x)
{
if(x)
{
自动[x,y]=yy;
}
}
获取gcc中的阴影警告(
-Wall-Wshadow-std=c++17
):


这是一个叮当作响的bug,如本文所述:。

编译字符串是什么样子的?您正在使用
-std=c++17
(或更高版本)?由于您可以从结构化绑定中使用
x
,因此我预期会出现阴影警告。请提供。
<source>: In function 'void bla(int)':

<source>:8:19: warning: declaration of 'auto x' shadows a parameter [-Wshadow]

    8 |         auto [x, y] = yy;

      |                   ^

<source>:4:14: note: shadowed declaration is here

    4 | void bla(int x)

      |          ~~~~^

<source>:8:14: warning: structured binding declaration set but not used [-Wunused-but-set-variable]

    8 |         auto [x, y] = yy;

      |              ^~~~~~
<source>:8:14: warning: unused variable '[x, y]' [-Wunused-variable]

        auto [x, y] = yy;

             ^

1 warning generated.