1

我一直在测试 clang-llvm,看看是否值得向我学校的 IT 部门提及以将其添加到我们学生编程的机器上。对于我们所有的作业,我们都需要使用 编译g++ -Wall -W -pedantic-errors *.cpp,所以我只是将命令转换为clang++ -Wall -W -pedantic-errors. 我得到了一些我没想到的输出:

Attempting to compile...
In file included from test_library.cpp:6:
In file included from ./test_library.h:64:
In file included from ./library.h:167:
./library.hpp:20:23: warning: unused variable 'e' [-Wunused-variable]
    catch(Exception & e)
                      ^

而 GCC 编译器不会给出关于 catch 块中未使用变量的错误。有什么我可以做的,以使 Clang 不会对 try/catch 块中未使用的变量感到害怕,同时保持与 g++ 相似的命令?

Clang-LLVM(v2.7) GNU GCC(v4.4.4) Fedora 13

4

2 回答 2

5

我有点同意迈克的观点,但为了起步起见,试试这个:

clang++ -Wall -W -pedantic-errors -Wno-unused-variable

我没有太多使用llvm,但我认为诊断中的重点[-Wunused-variable]是告诉你你可以关闭那个警告-Wno-unused-variable

于 2010-09-20T23:49:06.147 回答
3

如果您不使用该变量,使用“catch(Exception &)”捕获异常有什么问题?你的编译器和你的代码审查者会更开心。

于 2010-09-21T01:58:37.210 回答