Clang 的意外输出
我一直在测试 clang-llvm,看看是否值得向我学校的 IT 部门提及,将其添加到我们学生编程的机器上。对于我们所有的作业,我们都需要使用 g++ -Wall -W -pedantic-errors *.cpp 进行编译,因此我只是将命令转换为 clang++ -Wall -W -pedantic-错误。我得到了一些我没有预料到的输出:
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
I've been testing out clang-llvm to see if it is worth it to mention to my school's IT department to add it to the machines we students program on. For all of our assignments, we are required to compile using g++ -Wall -W -pedantic-errors *.cpp
, so I just converted the command to clang++ -Wall -W -pedantic-errors
. I got some output that I wasn't expecting:
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)
^
Whereas the GCC compiler does not give an error about unused variables in the catch block. Is there anything I can do so that Clang does not freak out about unused variables in try/catch blocks while keeping the command similar to the g++ one?
Clang-LLVM(v2.7) GNU GCC(v4.4.4) Fedora 13
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有点同意 Mike 的观点,但为了入门,尝试一下这个:
我没有太多使用 llvm,但我认为
[-Wunused-variable] 的要点诊断中的
是告诉您可以使用-Wno-unused-variable
关闭该警告。I kinda agree with Mike, but for getting-off-the-ground's sake, try this:
I haven't used llvm much but I think the point of the
[-Wunused-variable]
in the diagnostic is to tell you that you can shut that warning up with-Wno-unused-variable
.如果不使用变量,用“catch(Exception &)”捕获异常有什么问题?你们编译器和代码审查者会更高兴。
What's wrong with catching exception with "catch(Exception &)" if you are not using the variable? You compilers AND your code reviewers will be happier.