llvm-g++-4.2 和 C++新型铸造
我面临一个奇怪的问题。我查遍了 stackoverflow.com 和其他地方,但没有找到答案。
这是一些背景:我正在编写一个简单的库;主要用于教育目的并更好地理解 C++。我使用的是配备 Snow Leopard 的 MacBook Pro。我也安装了 Xcode 4.2,但是我只使用 VIM 来编辑代码。我最近完成了 GNU 构建系统的实现,因此我不必再依赖 Xcode,同时也不必编写和维护自定义 Makefile。我正在使用最高级别的警告。这是到目前为止我得到的标志(但我不断地增量添加它们,了解每个标志的原因): -Wall -Wmissing-field-initializers -Wno-trigraphs -Wreturn-类型-Wnon-virtual-dtor -Woverloaded-virtual -Wmissing-braces -Wparentheses -Wswitch -Wunused-value -Wsign-compare -Waddress -Wsequence-point -Wshorten-64-to-32 -Wwrite-strings -Wold-style-cast
,最后是-Werror
。
现在,我有一个非常简单地返回一个值的函数:
wint_t weof() {
return static_cast<wint_t>(WEOF);
}
但是,当我编译此代码时,我收到警告“使用旧式转换”。我不明白 static_cast<>
怎么会是“旧式”。有人可以向我解释为什么会发生这种情况吗?我以为我可以通过查看 WEOF
的定义找到答案,但在 Mac 上它被定义为 __DARWIN_WEOF
并且我似乎找不到它的定义。
谢谢!
I'm facing a weird problem. I looked around all over stackoverflow.com and elsewhere, but I didn't find an answer.
Here's some background: I'm writing a simple library; mostly for educational purposes and to understand C++ better. I'm using a MacBook Pro with Snow Leopard. I have an installation of Xcode 4.2 as well, however I use only VIM to edit my code. I recently finished implementing the GNU build system for whatever I have so far, so that I do not have to depend on Xcode anymore, and at the same time not have to write and maintain custom Makefiles. I'm using highest levels of warnings. Here're the flags I've got so far (but I keep adding on to them incrementally, understanding the reasons for each flag as I go): -Wall -Wmissing-field-initializers -Wno-trigraphs -Wreturn-type -Wnon-virtual-dtor -Woverloaded-virtual -Wmissing-braces -Wparentheses -Wswitch -Wunused-value -Wsign-compare -Waddress -Wsequence-point -Wshorten-64-to-32 -Wwrite-strings -Wold-style-cast
, and finally, -Werror
.
Now, I have a function which very simply returns a value:
wint_t weof() {
return static_cast<wint_t>(WEOF);
}
However, when I compile this code, I get the warning "use of old-style cast". I don't understand how static_cast<>
can be "old-style". Could anybody explain to me why this is happening? I thought I'd find the answer by looking at the definition of WEOF
, but on Mac it's defined to __DARWIN_WEOF
and I can't seem to find the definition of that.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最有可能的是
__DARWIN_WEOF
宏本身正在使用旧式转换(进行一些网络搜索,看起来该值可能是((__darwin_wint_t)-1)
)。如果您使用的是 C 兼容标头,则不太可能完全启用-Wold-style-cast
。作为解决方法,您可以尝试使用适当的
#pragma
包围任何违规代码以禁用此警告。但这可能会在一段时间后变得非常烦人/冗长......
Most likely the
__DARWIN_WEOF
macro itself is using an old-style cast (doing some web searching, it seems the value is likely((__darwin_wint_t)-1)
). If you are using C-compatible headers, it's unlikely you'll be able to fully enable-Wold-style-cast
.As a workaround, you could try surrounding any offending code with an appropriate
#pragma
to disable this warning.But this will probably get pretty tiresome/verbose after a while...