ric*_*cab 2 c++ gcc warnings auto unused-variables
使用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
Run Code Online (Sandbox Code Playgroud)
这是海湾合作委员会的不一致吗?
1.1如果是这样,在所有情况下应该发生什么,警告或没有警告?
1.2如果不是,行为不同的原因是什么?
注意:关于1.1,我想在这种情况下不应该打印警告(这就是clang所做的).否则,任何包含常量定义标头但不使用其中所有常量的编译单元都会包含大量警告.