您的位置:首页 > 其它

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编译默认开启,好奇怪。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  gcc