【转】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
.
-Werror
M
ake 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 diagnostic
kind 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 apop
has 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 message
string- 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头 ...
随机推荐
- 【转】Java如何克隆集合——深度拷贝ArrayList和HashSet
原文网址:http://blog.csdn.net/cool_sti/article/details/21658521 原英文链接:http://javarevisited.blogspot.hk/2 ...
- CSS flex让所有灵活的项目都带有相同的长度,忽略它们的内容:
.flexbox { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; displa ...
- 【POJ2777】Count Color(线段树)
以下是题目大意: 有水平方向上很多块板子拼成的墙,一开始每一块都被涂成了颜色1,有C和P两个操作,代表的意思是:C X Y Z —— 从X到Y将板子涂成颜色ZP X Y —— 查询X到Y的板子共 ...
- [置顶] API相关工作过往的总结之Sandcastle简要使用介绍
Sandcastle介绍 在微软推出Sandcastle之前,人们倾向于选择开源的NDoc(.NET代码文档生成器).NDo可以将 C#.NET 编译生成的程序集和对应的 /doc XML文档,自动转 ...
- c语言结构体4之结构体引用
struct mystruct{ char str[23];}; 1结构体变量不能整体引用 struct data m: printf("%s",m);//m是结构体变量 2 st ...
- c指针点滴5-指针变量计算
//接口dll _declspec(dllexport) void go() { char *p1; int *p2; p1 = (char*)0x30fa83;//每次运行exe的时候输出地址值不同 ...
- java_抽象类应用
本例子通过一个实例来具体阐述抽象类的应用,首先一个抽象类Person2,里面定义了一些人的共有属性(年龄,姓名),和抽象方法want(),want()方法来具体实现不同的人的需求(学生想要成绩,工人想 ...
- html5标签收集
<meta name="viewport" content="width=device-width,initial-scale=1 user-scalable=0& ...
- junit4测试 Spring MVC注解方式
本人使用的为junit4进行测试 spring-servlet.xml中使用的为注解扫描的方式 <?xml version="1.0" encoding="UTF- ...
- [转]iOS开发使用半透明模糊效果方法整理
转自:http://www.molotang.com/articles/1921.html 虽然iOS很早就支持使用模糊效果对图片等进行处理,但尤其在iOS7以后,半透明模糊效果得到大范围广泛使用.包 ...