gcc编译警告
2016-06-10 19:47
881 查看
1. gcc 6新增编译警告
1.1 literal-suffix——宏和字符串中间要加空格
unlink(FILE_DIR "/"TRIGSCENE_FILE);
警告内容:
invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
修复方法:
unlink(FILE_DIR "/" TRIGSCENE_FILE);
说明:实际上只要
unlink(FILE_DIR"/" TRIGSCENE_FILE);
即宏后面允许为字符串,而宏前面有字符串常量必须空一格。
1.2 misleading-indentation——缩进问题
if (m_nEvgeObject == 0) return -1; m_bShow = false;
警告内容:
if (m_nEvgeObject == 0) ^~ note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
感觉这问题经常在tab和空格混用时出现。
修复方法:
if (m_nEvgeObject == 0) return -1; m_bShow = false;
1.3 模板展开时机修改
#define malloc my_malloc #define free my_free
警告内容:
In file included from malloc_allocator.h:39:0, dlmalloc.h:11:18: error: 'std::my_free' has not been declared #define free my_free ^ dlmalloc.h:10:18: error: 'std::my_malloc' has not been declared #define malloc my_malloc ^
修复方法:
#define malloc(x) my_malloc(x) #define free(x) my_free(x)
2. gcc 5(x86)新增警告
2.1 unused-variable——静态变量未使用
static CXmlInstance& myInstance = CXmlInstance::GetInstance();
警告:
error: ‘myInstance’ defined but not used [-Werror=unused-variable] static CXmlInstance& myInstance = CXmlInstance::GetInstance(); ^
修复方法:
static CXmlInstance& myInstance __attribute__((unused)) = CXmlInstance::GetInstance();
注意:好像只在x86上Release编译默认开启,好奇怪。
相关文章推荐
- 在Windows平台下使用安装GCC(图)
- linux使用gcc编译c语言共享库步骤
- C/C++编译器GCC下的常用编译命令总结
- GCC 编译c程序的方法及过程解析
- Glusterfs的编译选项 #pragma GCC poison system popen
- 【笔记】CentOS上源码安装GCC 4.8.2
- 【笔记】CentOS
- Java调用动态链接库
- RHEL 4.7 (64bit) 环境安装 GCC 4.6 测试记录 (更新至gcc-4.6.1)
- GCC 5 即将发布
- [转载]Visual Studio, GCC, Clang, Intel 对 C++11 特性的支持一览表
- C++爱好者博客
- gcc工具的运用
- gdb的运用
- GCC内联汇编(1)Get started
- GCC内嵌汇编
- g++编译 参数 .
- RHEL5.3 gcc rpm包安装
- linux GCC 64位编程技巧