目前,我使用以下函数模板来抑制未使用的变量警告:
template<typename T>
void
unused(T const &) {
/* Do nothing. */
}
Run Code Online (Sandbox Code Playgroud)
但是,当从Linux移植到cygwin时,我现在在g ++ 3.4.4上遇到编译器错误(在linux上我是3.4.6,所以这可能是一个bug修复?):
Write.cpp: In member function `void* Write::initReadWrite()':
Write.cpp:516: error: invalid initialization of reference of type 'const volatile bool&' from expression of type 'volatile bool'
../../src/common/Assert.h:27: error: in passing argument 1 of `void unused(const T&) [with T = volatile bool]'
make[1]: *** [ARCH.cygwin/release/Write.o] Error 1
Run Code Online (Sandbox Code Playgroud)
未使用的参数是一个声明为的成员变量:
volatile bool readWriteActivated;
Run Code Online (Sandbox Code Playgroud)
这是编译器错误还是我的代码中的错误?
这是最小的测试用例:
template<typename T>
void unused(T const &) { }
int main() {
volatile bool x = …Run Code Online (Sandbox Code Playgroud)