【发布时间】:2014-11-12 18:08:19
【问题描述】:
使用 gcc(此处为 4.7.2)我收到关于未使用的自动变量的警告,但没有关于其他变量的警告:
// cvars.h
#ifndef CVARS_H_
#define CVARS_H_
const auto const_auto = "const_auto";
const char const_char_array[] = "const_char_array";
const char * const_char_star = "const_char_star";
const char use_me = 'u';
#endif // CVARS_H_
//---
//comp_unit.cpp
#include "cvars.h"
void somef()
{
//const_auto // commented out - unused
use_me; // not using any of the others either
}
// compile with $ g++ -std=c++11 -Wunused-variable -c comp_unit.cpp
// gcc outputs warning: ‘cvars::const_auto’ defined but not used [-Wunused-variable]
// but does not complain about the other variables
-
这是 GCC 中的不一致吗?
1.1 如果是这样,在所有情况下应该发生什么,警告还是不警告?
1.2 如果不是,行为差异的原因是什么?
注意:关于 1.1,我想在这种情况下不应该打印任何警告(这就是 clang 所做的)。否则,任何包含常量定义标头但未使用其中所有常量的编译单元都会包含大量警告。
【问题讨论】:
标签: c++ gcc warnings auto unused-variables