【转】GCC4.6编译的warning -Werror
原文网址:http://blog.sina.com.cn/s/blog_605f5b4f0101bct7.html
New warnings for unused variables and parameters
The behavior of -Wall has changed and now includes the new warning flags -Wunused-but-set-variable and (with -Wall -Wextra) -Wunused-but-set-parameter. This may result in new warnings in code that compiled cleanly with previous versions of GCC.
For example,
void fn (void)
{
int foo;
foo = bar ();
}
Gives the following diagnostic:
warning: variable "foo" set but not used [-Wunused-but-set-variable]
Although these warnings will not result in compilation failure, often -Wall is used in conjunction with -Werror and as a result, new warnings are turned into new errors.
To fix, first see if the unused variable or parameter can be removed without changing the result or logic of the surrounding code. If not, annotate it with __attribute__((__unused__)).
As a workaround, add -Wno-error=unused-but-set-variable or -Wno-error=unused-but-set-parameter.
-WerrorMake all warnings into errors- -Wall
- -Wall turns on the following warning flags:
- --Waddress
- -Warray-bounds (only with -O2)
- -Wc++11-compat
- -Wchar-subscripts
- -Wenum-compare (in C/ObjC; this is on by default in C++)
- -Wimplicit-int (C and Objective-C only)
- -Wimplicit-function-declaration (C and Objective-C only)
- -Wcomment
- -Wformat
- -Wmain (only for C/ObjC and unless -ffreestanding)
- -Wmaybe-uninitialized
- -Wmissing-braces (only for C/ObjC)
- -Wnonnull
- -Wparentheses
- -Wpointer-sign
- -Wreorder
- -Wreturn-type
- -Wsequence-point
- -Wsign-compare (only in C++)
- -Wstrict-aliasing
- -Wstrict-overflow=1
- -Wswitch
- -Wtrigraphs
- -Wuninitialized
- -Wunknown-pragmas
- -Wunused-function
- -Wunused-label
- -Wunused-value
- -Wunused-variable
- -Wvolatile-register-var
-Wextra
This enables some extra warning flags that are not enabled by -Wall. (This option used to be called -W. The older name is still supported, but the newer name is more descriptive.)
-Wclobbered
-Wempty-body
-Wignored-qualifiers
-Wmissing-field-initializers
-Wmissing-parameter-type (C only)
-Wold-style-declaration (C only)
-Woverride-init
-Wsign-compare
-Wtype-limits
-Wuninitialized
-Wunused-parameter (only with -Wunused or -Wall)
-Wunused-but-set-parameter (only with -Wunused or -Wall)
Warn whenever a function parameter is assigned to, but otherwise unused (aside from its declaration).
To suppress this warning use the ‘unused’ attribute (see Variable Attributes).
This warning is also enabled by -Wunused together with -Wextra.
-Wunused-but-set-parameter
Warn whenever a function parameter is assigned to, but otherwise unused (aside from its declaration).
To suppress this warning use the ‘unused’ attribute (see Variable Attributes).
This warning is also enabled by -Wunused together with -Wextra.
-Wunused-but-set-variable
Warn whenever a local variable is assigned to, but otherwise unused (aside from its declaration). This warning is enabled by -Wall.
To suppress this warning use the ‘unused’ attribute (see Variable Attributes).
This warning is also enabled by -Wunused, which is enabled by -Wall.
-Wunused-function
Warn whenever a static function is declared but not defined or a non-inline static function is unused. This warning is enabled by -Wall.
-Wunused-label
Warn whenever a label is declared but not used. This warning is enabled by -Wall.To suppress this warning use the ‘unused’ attribute (see Variable Attributes).
-Wunused-local-typedefs (C, Objective-C, C++ and Objective-C++ only)
Warn when a typedef locally defined in a function is not used. This warning is enabled by -Wall.
-Wunused-parameter
Warn whenever a function parameter is unused aside from its declaration.
To suppress this warning use the ‘unused’ attribute (see Variable Attributes).
6.61.10 Diagnostic Pragmas
https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html
GCC allows the user to selectively enable or disable certain types of diagnostics, and change the kind of the diagnostic. For example, a project's policy might require that all sources compile with -Werror but certain files might have exceptions allowing specific types of warnings. Or, a project might selectively enable diagnostics and treat them as errors depending on which preprocessor macros are defined.
#pragma GCC diagnostickind option- Modifies the disposition of a diagnostic. Note that not all diagnostics are modifiable; at the moment only warnings (normally controlled by ‘-W...’) can be controlled, and not all of them. Use -fdiagnostics-show-option to determine which diagnostics are controllable and which option controls them.
kind is ‘error’ to treat this diagnostic as an error, ‘warning’ to treat it like a warning (even if -Werror is in effect), or ‘ignored’ if the diagnostic is to be ignored. option is a double quoted string that matches the command-line option.
#pragma GCC diagnostic warning "-Wformat"
#pragma GCC diagnostic error "-Wformat"
#pragma GCC diagnostic ignored "-Wformat"Note that these pragmas override any command-line options. GCC keeps track of the location of each pragma, and issues diagnostics according to the state as of that point in the source file. Thus, pragmas occurring after a line do not affect diagnostics caused by that line.
#pragma GCC diagnostic push#pragma GCC diagnostic pop- Causes GCC to remember the state of the diagnostics as of each
push, and restore to that point at eachpop. If apophas no matchingpush, the command-line options are restored.#pragma GCC diagnostic error "-Wuninitialized"
foo(a); /* error is given for this one */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuninitialized"
foo(b); /* no diagnostic for this one */
#pragma GCC diagnostic pop
foo(c); /* error is given for this one */
#pragma GCC diagnostic pop
foo(d); /* depends on command-line options */
GCC also offers a simple mechanism for printing messages during compilation.
#pragma messagestring- Prints string as a compiler message on compilation. The message is informational only, and is neither a compilation warning nor an error.
#pragma message "Compiling " __FILE__ "..."
string may be parenthesized, and is printed with location information. For example,
#define DO_PRAGMA(x) _Pragma (#x)
#define TODO(x) DO_PRAGMA(message ("TODO - " #x)) TODO(Remember to fix this)prints ‘/tmp/file.c:4: note: #pragma message: TODO - Remember to fix this’.
【转】GCC4.6编译的warning -Werror的更多相关文章
- App开发流程之使用分类(Category)和忽略编译警告(Warning)
Category使得开发过程中,减少了继承的使用,避免子类层级的膨胀.合理使用,可以在不侵入原类代码的基础上,写出漂亮的扩展内容.我更习惯称之为"分类". Category和Ext ...
- 将Linux下编译的warning警告信息输出到文件中[整理笔记]
Linux中,脚本语言环境中,即你用make xxx即其他一些普通linux命令,比如ls,find等,不同的数字,代表不同的含义: 数字 含义 标准叫法0 标准输入 stdin = standar ...
- 16种C语言编译警告(Warning)类型的解决方法
当编译程序发现程序中某个地方有疑问,可能有问题时就会给出一个警告信息.警告信息可能意味着程序中隐含的大错误,也可能确实没有问题.对于警告的正确处理方式应该是:尽可能地消除之.对于编译程序给出的每个警告 ...
- 简单编写makefile文件,实现GCC4.9编译项目,增加boost库測试等等。。
一.须要用到的hw.cpp hw.h funtest.cpp funtest.h makefile 几个測试文件 1.hw.cpp代码例如以下: #include "hw.h" # ...
- CMake编译如何解决[-Werror,-Wformat-security] 问题
在用Android Studio进行Android开发时,常常采用 java代码调用C++代码,即JNI调用native的开发模式. 在上层build.gradle编译脚本里面可以指定C++代码的编译 ...
- C语言 消灭编译警告(Warning)
如何看待编译警告 当编译程序发现程序中某个地方有疑问,可能有问题时就会给出一个警告信息.警告信息可能意味着程序中隐含的大错误,也可能确实没有问题.对于警告的正确处理方式应该是:尽可能地消除之.对于编译 ...
- centos5.6部署gcc4.7编译的程序导致问题
因为用了c++0x的一些新特性,必须使用4.6及以上的版本编译,所以使用了4.7编译,运行时提示错误 libstdc++.so.6(GLIBCXX_3.4.14) 错误 这个时候下了个glibc2.7 ...
- 编译出现 WARNING: 'aclocal-1.15' is missing on your system.问题解决
1. ubuntu14.04 出现这个问题,需要手动安装 Automake-1.15 2. 下载地址: http://ftp.gnu.org/gnu/automake/ http://ftp.gnu. ...
- 编译错误:warning C4005]ws2def.h(91): warning C4005: “AF_IPX”: 宏重定义 winsock.h(460) : 参见“AF_IPX”的前一个定义
[问题] ws2def.h(91): warning C4005: “AF_IPX”: 宏重定义: winsock2.h(460) : 参见“AF_IPX”的前一个定义 [原因] windows.h头 ...
随机推荐
- SOSP 文档 - Windows Azure 存储:具有强一致性的高可用性云存储服务
之前,我们在第 23 届 ACM操作系统原理研讨会 (SOSP)上发布了一篇文章,其中介绍了 Windows Azure存储的内部详细信息. 您可以在此处找到该文章.此次大会还发布了一段视频讲话( ...
- (1) 一个字符串,根据输入参数m,找出字符串的m个字符的所有字符串
/** * 有一个字符串,根据输入参数m,找出字符串的m个字符的所有字符串 例如: String str ="abc", m=2 得到结果是 "ab" &quo ...
- <php>上传文件的程序
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Ubuntu 无线连接能上网,但是有线连接不能上
这两天装Ubuntu,遇到小问题.最头疼的还是上网,过去我装了Ubuntu时,都是插上网线就能直接上网,这次就不行了. 我刚点开一个网页,接下来点就不能上了,但是无线连接就可以正常上网. 我在一个论坛 ...
- SpringMVC接收复杂集合参数
Spring MVC在接收集合请求参数时,需要在Controller方法的集合参数里前添加@RequestBody,而@RequestBody默认接收的enctype (MIME编码)是applica ...
- hdu 4640 Island and study-sister
bfs+状态压缩求出所有的状态,然后由于第一个节点需要特殊处理,可以右移一位剔除掉,也可以特判.然后采用集合的操作, #pragma comment(linker,"/STACK:10240 ...
- 在线C语言编译器/解释器
在线C语言编译器/解释器 本文介绍两个C语言在线解释器/编译器,这些工具可以提高代码片段检测方便的工作效率,并可以保证这些代码的正确性,而且还可以和别人一起编辑/分享之间的代码,这样可以共同分析代码并 ...
- HADOOP集群监控工具AMBARI
HADOOP集群监控工具AMBARI安装 Apache Ambari是对Hadoop进行监控.管理和生命周期管理的开源项目.它也是一个为Hortonworks数据平台选择管理组建的项目.Ambari向 ...
- OC教程10-NSNumber具体
NSNumber简单介绍 NSNumber是数字的对象形式,由于在OC的数组和字典中仅仅同意存放对象,所以我们有时候须要转化 我们普通的类型是 123 那么 NSNumber类型的是 @123, ...
- jQuery制作焦点图(轮播图)
焦点图(轮播图) 案例 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ ...