Clang 的意外输出

发布于 2024-09-24 05:27:32 字数 629 浏览 10 评论 0原文

我一直在测试 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青衫负雪 2024-10-01 05:27:32

我有点同意 Mike 的观点,但为了入门,尝试一下这个:

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

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

I kinda agree with Mike, but for getting-off-the-ground's sake, try this:

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

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.

痞味浪人 2024-10-01 05:27:32

如果不使用变量,用“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文