禁止在C ++ =>中使用未使用的变量警告.编译器错误还是代码错误? [英] Suppress unused variable warning in C++ => Compiler bug or code bug?

查看:234
本文介绍了禁止在C ++ =>中使用未使用的变量警告.编译器错误还是代码错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在使用以下功能模板来抑制未使用的变量警告:

Presently, I am using the following function template to suppress unused variable warnings:

template<typename T>
void
unused(T const &) {
  /* Do nothing. */
}

但是,当从Linux移植到cygwin时,我现在在g ++ 3.4.4上遇到编译器错误(在Linux上我是3.4.6,所以也许这是一个错误修复?):

However, when porting to cygwin from Linux, I am now getting compiler errors on g++ 3.4.4 (On linux I am 3.4.6, so maybe this is a bug fix?):

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

unused的参数是声明为的成员变量:

The argument to unused is a member variable declared as:

  volatile bool readWriteActivated;

这是编译器错误还是代码中的错误?

Is this a compiler bug or a bug in my code?

这是最小的测试用例:

template<typename T>
void unused(T const &) { }

int main() {
  volatile bool x = false;
  unused(!x); // type of "!x" is bool
}

推荐答案

这是一个编译器错误,没有已知的解决方法:

It is a compiler bug and there are no known work arounds:

http://gcc.gnu.org/bugzilla/show_bug.cgi ?id = 42655

在v4.4中已修复.

这篇关于禁止在C ++ =>中使用未使用的变量警告.编译器错误还是代码错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆