我是靠谱客的博主 花痴过客,这篇文章主要介绍Gcc编译时出现 [-Werror=unused-parameter],现在分享给大家,希望可以做个参考。

项目在开发的时候可能要求将所有的warning 都暴露出来,在gcc 编译的时候需要加上flag -Wall。

如果没有使用的变量或者函数,就会在这个时候暴露出来,并提示如下信息:

复制代码
1
error: unused parameter ‘spid’ [-Werror=unused-parameter]

这里总结下解决的办法:

1. 当然就是将flag 去掉,不要提示,这个属于下下策。

2. 找到对应的地方进行处理

仅需在头文件中添加:

复制代码
1
#define UNUSED(x) (void)(x)

补充,

-Wall 将打开的 warning flags:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
-Waddress -Warray-bounds=1 (only with -O2) -Warray-compare -Warray-parameter=2 (C and Objective-C only) -Wbool-compare -Wbool-operation -Wc++11-compat -Wc++14-compat -Wcatch-value (C++ and Objective-C++ only) -Wchar-subscripts -Wcomment -Wdangling-pointer=2 -Wduplicate-decl-specifier (C and Objective-C only) -Wenum-compare (in C/ObjC; this is on by default in C++) -Wenum-int-mismatch (C and Objective-C only) -Wformat -Wformat-overflow -Wformat-truncation -Wint-in-bool-context -Wimplicit (C and Objective-C only) -Wimplicit-int (C and Objective-C only) -Wimplicit-function-declaration (C and Objective-C only) -Winit-self (only for C++) -Wlogical-not-parentheses -Wmain (only for C/ObjC and unless -ffreestanding) -Wmaybe-uninitialized -Wmemset-elt-size -Wmemset-transposed-args -Wmisleading-indentation (only for C/C++) -Wmismatched-dealloc -Wmismatched-new-delete (only for C/C++) -Wmissing-attributes -Wmissing-braces (only for C/ObjC) -Wmultistatement-macros -Wnarrowing (only for C++) -Wnonnull -Wnonnull-compare -Wopenmp-simd -Wparentheses -Wpessimizing-move (only for C++) -Wpointer-sign -Wrange-loop-construct (only for C++) -Wreorder -Wrestrict -Wreturn-type -Wself-move (only for C++) -Wsequence-point -Wsign-compare (only in C++) -Wsizeof-array-div -Wsizeof-pointer-div -Wsizeof-pointer-memaccess -Wstrict-aliasing -Wstrict-overflow=1 -Wswitch -Wtautological-compare -Wtrigraphs -Wuninitialized -Wunknown-pragmas -Wunused-function -Wunused-label -Wunused-value -Wunused-variable -Wuse-after-free=2 -Wvla-parameter (C and Objective-C only) -Wvolatile-register-var -Wzero-length-bounds

 -Wextra 额外使能的waring flags:

这些flags 通过 -Wall 也无法使能的。 

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-Wclobbered -Wcast-function-type -Wdeprecated-copy (C++ only) -Wempty-body -Wenum-conversion (C only) -Wignored-qualifiers -Wimplicit-fallthrough=3 -Wmissing-field-initializers -Wmissing-parameter-type (C only) -Wold-style-declaration (C only) -Woverride-init -Wsign-compare (C only) -Wstring-compare -Wredundant-move (only for C++) -Wtype-limits -Wuninitialized -Wshift-negative-value (in C++11 to C++17 and in C99 and newer) -Wunused-parameter (only with -Wunused or -Wall) -Wunused-but-set-parameter (only with -Wunused or -Wall)

 

参考:

Warning Options (Using the GNU Compiler Collection (GCC))

最后

以上就是花痴过客最近收集整理的关于Gcc编译时出现 [-Werror=unused-parameter]的全部内容,更多相关Gcc编译时出现内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部