Visual Studio const_iterator分配错误 [英] Visual Studio const_iterator Assignment Error
问题描述
在Visual Studio 2010上分配一个默认构造的向量< int *> :: const_iterator
错误。我在5个Visual Studio 2010系统上试过,有Service Pack 1.它在3/5机器上失败,我已经能够识别3个系统上导致故障的原因,但我似乎找不到错误报告。
The assignment of a default constructed vector<int*>::const_iterator
errors on Visual Studio 2010. I've tried this on 5 Visual Studio 2010 systems that all have Service Pack 1. It fails on 3/5 machines, I've been able to identify what is causing the failure on the 3 systems but I cannot seem to find a bug report.
这里是代码:
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int*> vec;
int arr[3] = {};
for(int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) vec.push_back(arr + i);
vector<int*>::const_iterator initialized = vec.cbegin();
vector<int*>::const_iterator uninitialized;
initialized = uninitialized;
cout << "Hello World" << endl;
return 0;
}
显然,除了 cout< Hello World< endl;
在Release中进行了优化,因此这个最小示例只会在Debug中失败。但在Debug中,它给出的错误是:
Clearly everything but the cout << "Hello World" << endl;
is optimized out in Release so this minimal example will only fail in Debug. But in Debug the error it gives is:
在test.exe中0x01071e14处的未处理异常:0xC0000005:访问冲突读取位置0x00000000。 p>
Unhandled exception at 0x01071e14 in test.exe: 0xC0000005: Access violation reading location 0x00000000.
比较链接的工作和非工作MSVCP100D.dll显示存在微小差异,工作.dll是产品版本: 10.0.40219.325和非工作的.dll是产品版本:10.0.40219.1。
Comparing the working and non-working MSVCP100D.dlls that were linked shows that there is a slight discrepancy, the working .dll is Product Version: 10.0.40219.325 and the non-working .dll is Product Version: 10.0.40219.1.
实际错误发生在
C:\Program Files(x86)\ Microsoft Visual Studio 10.0 \VC\include\xutility
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility
再次区分工作版本和非工作版本显示已对工作版本进行了更改。非工作代码简单地说:
And again diffing the working and non-working version shows that a change has been made to the working version. The non-working code simply says:
if (_Myproxu != _Right._Myproxy)
_Adopt(_Right._Myproxy->_Mycont);
工作代码说:
if (_Myproxy == _Right._Myproxy)
;
else if (_Right._Myproxy != 0)
_Adopt(_Right._Myproxy->_Mycont);
else
{ // becoming invalid, disown current parent
_Lockit _Lock(_LOCK_DEBUG);
_Orphan_me();
}
这就是我的实际问题。如何获取此更新?我已更新到最新使用Windows更新,但问题还没有解决。有没有一些隐藏的补丁,我需要去某个地方得到?我找不到这个问题写在任何地方,所以我也找不到有关补丁的信息。
All that to say, here's my actual question. How do I get this update? I've updated to the latest using Windows Update, but the problem has not been resolved. Is there some hidden patch that I need to go somewhere to get? I can't find this issue written up anywhere, so I also can't find information about the patch.
推荐答案
有未定义的行为。 [iterator.requirements.general] / p6:
This code has undefined behavior. [iterator.requirements.general]/p6:
迭代器也可以有与
任何序列无关的奇异值。 [示例:在声明未初始化的
指针x
之后(如int * x;
),x
必须总是假定有一个指针的
奇异值。 - end example ]大多数
表达式的结果未定义为奇异值;唯一的例外是
破坏一个拥有奇异值的迭代器,将
a非奇异值赋值给一个拥有奇异值的迭代器,
用于满足DefaultConstructible
需求,
使用值初始化的迭代器作为副本或移动
操作的源。 [注意::此保证不提供默认
初始化,虽然区别只对具有
类型的类型有意义,例如指针或聚合保存
指针的默认构造函数。 - end note ]在这些情况下,奇异值是
覆盖的方式与任何其他值相同。可拒绝值
总是非奇异的。
Iterators can also have singular values that are not associated with any sequence. [ Example: After the declaration of an uninitialized pointer
x
(as withint* x;
),x
must always be assumed to have a singular value of a pointer. —end example ] Results of most expressions are undefined for singular values; the only exceptions are destroying an iterator that holds a singular value, the assignment of a non-singular value to an iterator that holds a singular value, and, for iterators that satisfy theDefaultConstructible
requirements, using a value-initialized iterator as the source of a copy or move operation. [ Note: This guarantee is not offered for default initialization, although the distinction only matters for types with trivial default constructors such as pointers or aggregates holding pointers. —end note ] In these cases the singular value is overwritten the same way as any other value. Dereferenceable values are always non-singular.
未初始化
但是,考虑到你发布的代码段,我怀疑你的代码不会即使您的值初始化未初始化
,这是Microsoft的实现中的错误,并且它们在后续修补程序。
However, given the snippets you post, I suspect that your code wouldn't work either even if you value-initialize uninitialized
, which is a bug in Microsoft's implementation, and which they fixed in a later hotfix.
这篇关于Visual Studio const_iterator分配错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!