草庐IT

withProtectedClose

全部标签

c++ - 编译器是否应该忽略导致运行构造函数或析构函数的未使用变量?

我有一些代码放在析构函数中以确保它在正常退出和异常堆栈展开时运行:structwithProtectedClose{~withProtectedClose(){//Dosomecleanuphere...}};voidtest(){withProtectedCloseclose;//Dosomeworkbeforeclosing}然而g++编译器(g++(GCC)3.4.620060404(RedHat3.4.6-11))正在提示:test.cpp:Infunction`voidtest()':test.cpp:28:warning:unusedvariable'close'我可以通过