来自Clang的意外输出

时间:2010-09-20 23:34:14

标签: c++ clang llvm-clang

我一直在测试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

2 个答案:

答案 0 :(得分:5)

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

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

我没有使用llvm,但我认为诊断中[-Wunused-variable]的要点是告诉您可以使用-Wno-unused-variable关闭该警告。

答案 1 :(得分:3)

如果您没有使用变量,使用“catch(Exception&)”捕获异常有什么问题?您的编译器和您的代码审阅者会更高兴。

相关问题