forked from OSchip/llvm-project
Remove undefined behavior from some tests. Thanks to Walter Brown for the heads-up.
llvm-svn: 251802
This commit is contained in:
parent
7c1f36a6b7
commit
8eb1d544f8
|
@ -20,13 +20,15 @@
|
|||
struct B
|
||||
{
|
||||
static int count_;
|
||||
static int population_;
|
||||
int data_;
|
||||
explicit B() : data_(1) {}
|
||||
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
|
||||
~B() {data_ = 0;}
|
||||
explicit B() : data_(1) { ++population_; }
|
||||
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_; ++population_; }
|
||||
~B() {data_ = 0; --population_; }
|
||||
};
|
||||
|
||||
int B::count_ = 0;
|
||||
int B::population_ = 0;
|
||||
|
||||
struct Nasty
|
||||
{
|
||||
|
@ -45,6 +47,7 @@ int main()
|
|||
char pool[sizeof(B)*N] = {0};
|
||||
B* bp = (B*)pool;
|
||||
B b[N];
|
||||
assert(B::population_ == N);
|
||||
try
|
||||
{
|
||||
std::uninitialized_copy(b, b+N, bp);
|
||||
|
@ -52,14 +55,15 @@ int main()
|
|||
}
|
||||
catch (...)
|
||||
{
|
||||
for (int i = 0; i < N; ++i)
|
||||
assert(bp[i].data_ == 0);
|
||||
assert(B::population_ == N);
|
||||
}
|
||||
B::count_ = 0;
|
||||
std::uninitialized_copy(b, b+2, bp);
|
||||
for (int i = 0; i < 2; ++i)
|
||||
assert(bp[i].data_ == 1);
|
||||
assert(B::population_ == N + 2);
|
||||
}
|
||||
|
||||
{
|
||||
const int N = 5;
|
||||
char pool[sizeof(Nasty)*N] = {0};
|
||||
|
|
|
@ -20,12 +20,14 @@
|
|||
struct B
|
||||
{
|
||||
static int count_;
|
||||
static int population_;
|
||||
int data_;
|
||||
explicit B() : data_(1) {}
|
||||
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
|
||||
~B() {data_ = 0;}
|
||||
explicit B() : data_(1) { ++population_; }
|
||||
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_; ++population_; }
|
||||
~B() {data_ = 0; --population_; }
|
||||
};
|
||||
|
||||
int B::population_ = 0;
|
||||
int B::count_ = 0;
|
||||
|
||||
struct Nasty
|
||||
|
@ -45,6 +47,7 @@ int main()
|
|||
char pool[sizeof(B)*N] = {0};
|
||||
B* bp = (B*)pool;
|
||||
B b[N];
|
||||
assert(B::population_ == N);
|
||||
try
|
||||
{
|
||||
std::uninitialized_copy_n(b, 5, bp);
|
||||
|
@ -52,14 +55,15 @@ int main()
|
|||
}
|
||||
catch (...)
|
||||
{
|
||||
for (int i = 0; i < N; ++i)
|
||||
assert(bp[i].data_ == 0);
|
||||
assert(B::population_ == N);
|
||||
}
|
||||
B::count_ = 0;
|
||||
std::uninitialized_copy_n(b, 2, bp);
|
||||
for (int i = 0; i < 2; ++i)
|
||||
assert(bp[i].data_ == 1);
|
||||
assert(B::population_ == N + 2);
|
||||
}
|
||||
|
||||
{
|
||||
const int N = 5;
|
||||
char pool[sizeof(Nasty)*N] = {0};
|
||||
|
|
Loading…
Reference in New Issue