visual-c++ - 为什么/Wp64 已被弃用?

标签 visual-c++ deprecated compiler-flags

为什么是/Wp64 Visual C++ 中的标志 deprecated ?

cl : Command line warning D9035 :
option 'Wp64' has been deprecated and will be removed in a future release

最佳答案

我认为/Wp64已弃用,主要是因为针对 64 位目标进行编译将捕获它旨在捕获的错误类型(/Wp64 仅在 32 位编译中有效)。当 64 位目标出现时,该选项被添加回来,以帮助人们将他们的程序迁移到 64 位并帮助检测不是“64 位干净”的代码。

以下是 /Wp64 的各种问题的示例微软只是对修复不感兴趣 - 可能是正确的(来自 http://connect.microsoft.com/VisualStudio/feedback/details/502281/std-vector-incompatible-with-wp64-compiler-option ):

Actually, the STL isn't intentionally incompatible with /Wp64, nor is it completely and unconditionally incompatible with /Wp64. The underlying problem is that /Wp64 interacts extremely badly with templates, because __w64 isn't fully integrated into the type system. Therefore, if vector<unsigned int> is instantiated before vector<__w64 unsigned int>, then both of them will behave like vector<unsigned int>, and vice versa. On x86, SOCKET is a typedef for __w64 unsigned int. It's not obvious, but vector<unsigned int> is being instantiated before your vector<SOCKET>, since vector<bool> is backed (in our implementation) by vector<unsigned int>.

Previously (in VC9 and earlier), this bad interaction between /Wp64 and templates caused spurious warnings. In VC10, however, changes to the STL have made this worse. Now, when vector::push_back() is given an element of the vector itself, it figures out the element's index before doing other work. That index is obtained by subtracting the element's address from the beginning of the vector. In your repro, this involves subtracting const SOCKET * - unsigned int *. (The latter is unsigned int * and not SOCKET * due to the previously described bug.) This /should/ trigger a spurious warning, saying "I'm subtracting pointers that point to the same type on x86, but to different types on x64". However, there is a SECOND bug here, where /Wp64 gets really confused and thinks this is a hard error (while adding constness to the unsigned int *).

We agree that this bogus error message is confusing. However, since it's preceded by an un-silenceable command line deprecation warning D9035, we believe that that should be sufficient. D9035 already says that /Wp64 shouldn't be used (although it doesn't go on to say "this option is super duper buggy, and completely unnecessary now").

In the STL, we could #error when /Wp64 is used. However, that would break customers who are still compiling with /Wp64 (despite the deprecation warning) and aren't triggering this bogus error. The STL could also emit a warning, but the compiler is already emitting D9035.

关于visual-c++ - 为什么/Wp64 已被弃用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7171295/

相关文章:

C++ Diamond 控制台输出问题

swift - 'init(源 :)' was deprecated in OS X 10. 14:核心图像内核语言 API 已弃用

ios - SoundCloud iOS SDK 过时了吗?

java - 设置 Java 编译器合规性级别

node.js - 如何根据具有相对位置的共享库构建 nodejs C++ 插件

kotlin - 如何在 Gradle 构建中使用来自 Kotlin 的孵化 Vector API?

c++ - 使用Visual C++构建mongodb源码出错

c++ - 由于 "Error LNK2028: unresolved token...",我无法编译解决方案

c++ - 使用 CreateEvent 创建/打开一个已经存在的偶数是否会重置信号?

html - 为什么 <ol> 和 <dl> 没有被弃用?