不同编译器会一致触发警告吗?
在写完这个问题 它在编译时显示解决方案并出现错误,我想知道是否有可能收到警告并完成编译(如问题中实际指定的那样)。
虽然诊断通常依赖于编译器,但对于某些代码来说,很明显会触发错误(例如访问不存在的成员或尝试实例化不完整类型的对象)。
但对于警告却不能这样说,因为编译器之间的警告往往有很大差异。尽管可以合理地假设用 GCC 触发的警告也会用 Clang 触发,但对于 Visual C++ 却不能这样说。
问题:
哪些警告(如果有)会在所有三个提到的编译器上一致触发?
VC++ 上的 /W3
以及 GCC 和 GCC 上的 -Wall
。可以假设 Clang。
请注意,这不仅对于该问题有用,而且对于触发用户定义消息的警告也可能有用。
After writing an answer to this question which displays the solution at compile time with an error, I wondered if it was possible to get a warning instead and finish compilation (as is actually specified in the question).
While diagnostics in general are compiler-dependant, it's pretty obvious for some code that an error will get triggered (such as accessing a non-existent member or trying to instantiate an object of incomplete type).
The same can't be said for warnings though, since these tend to differ a great deal between compilers. Even though it's reasonable to assume that warnings triggered with GCC will also get triggered with Clang, the same can not be said for Visual C++.
Question:
Which warnings, if any, will consistently get triggered on all three mentioned compilers?
/W3
on VC++ and -Wall
on GCC & Clang may be assumed.
Note that this is not only useful for that question, but may be useful for triggering a warning for user-defined messages aswell.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该适用于 MSVC、GCC 和 Clang:
不是很有用,但仍然有效。
这些也收到警告:
This should work on MSVC, GCC, and Clang:
Not very useful, but still works.
These picked up warnings too: