抑制C ++中未使用的变量警告=>编译器错误或代码错误? [英] Supress unused variable warning in C++ => Compiler bug or code bug?

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

问题描述

目前,我使用以下函数模板来抑制未使用的变量警告:

  template< typename T& 
void
unused(T const&){
/ *什么也不做。然而,当从Linux移植到cygwin时,我现在正在获取编译器(编译器),因为它是一个非常简单的编译器。在g ++上的错误3.4.4(在linux我是3.4.6,所以也许这是一个错误修复?):

  .cpp:在成员函数`void * Write :: initReadWrite()':
Write.cpp:516:error:无效初始化类型'const volatile bool&'从类型'volatile bool'
../../src/common/Assert.h:27:error:在传递`void unused(const T&)[的参数1] [with T = volatile bool]'
make [1] :*** [ARCH.cygwin / release / Write.o]错误1

是一个成员变量,声明为:

  volatile bool readWriteActivated; 

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



这里是最小测试用例:

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

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


解决方案

这是一个编译器错误,没有已知的工作环境:



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



它在v4.4中是固定的。


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

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

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

The argument to unused is a member variable declared as:

  volatile bool readWriteActivated;

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

Here is the minimal test case:

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

It is fixed in v4.4.

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

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