如何使用 -Wall 启用 -Wunused-variable?

How to enable -Wunused-variable with -Wall?

我正在使用以下命令构建 C++14。

g++ -std=c++14 -O2 -Wall -pedantic -pthread main.cpp && ./a.out

如何将 -Wunused-variable 添加到上面的行,以便显示除 -Wunused-variable 之外的所有警告?

来自gcc docs

You can request many specific warnings with options beginning with ‘-W’, for example -Wimplicit to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning ‘-Wno-’ to turn off warnings; for example, -Wno-implicit.

所以要禁用未使用的变量警告,您可以传递 -Wno-unused-variable