仅在 x64 版本中存在访问冲突
Access violation only in release x64
我在 <random>
header 的非常奇怪的情况下遇到访问冲突。这是编译器错误吗?这是代码:
#include <random>
class Foo {
public:
std::random_device rd;
std::mt19937_64 mt;
std::uniform_int_distribution<int> dist;
Foo();
};
Foo::Foo() : mt(rd()) {
dist = std::uniform_int_distribution<int>(0, 1);
}
int main() {
Foo foo;
int a[2];
int b[2] = { 0 };
for (int i = 0; i < 2; i++) {
int c = foo.dist(foo.mt);
a[0] = b[c];
b[c] = b[0];
}
}
如果我将 for-loop 替换为以下内容,代码将不会出现访问冲突!
{
int c = foo.dist(foo.mt);
a[0] = b[c];
b[c] = b[0];
}
{
int c = foo.dist(foo.mt);
a[0] = b[c];
b[c] = b[0];
}
这仅适用于版本 x64,我从 "Empty project" 开始。对我来说,这似乎是一个错误。我错过了什么吗?
这是优化器的一个错误,它将用于有符号整数的模式应用于无符号整数。
我报告了这个错误,Microsoft 的 David Hartglass 回复了 here。该错误目前正在处理中。
我在 <random>
header 的非常奇怪的情况下遇到访问冲突。这是编译器错误吗?这是代码:
#include <random>
class Foo {
public:
std::random_device rd;
std::mt19937_64 mt;
std::uniform_int_distribution<int> dist;
Foo();
};
Foo::Foo() : mt(rd()) {
dist = std::uniform_int_distribution<int>(0, 1);
}
int main() {
Foo foo;
int a[2];
int b[2] = { 0 };
for (int i = 0; i < 2; i++) {
int c = foo.dist(foo.mt);
a[0] = b[c];
b[c] = b[0];
}
}
如果我将 for-loop 替换为以下内容,代码将不会出现访问冲突!
{
int c = foo.dist(foo.mt);
a[0] = b[c];
b[c] = b[0];
}
{
int c = foo.dist(foo.mt);
a[0] = b[c];
b[c] = b[0];
}
这仅适用于版本 x64,我从 "Empty project" 开始。对我来说,这似乎是一个错误。我错过了什么吗?
这是优化器的一个错误,它将用于有符号整数的模式应用于无符号整数。
我报告了这个错误,Microsoft 的 David Hartglass 回复了 here。该错误目前正在处理中。