Remove undefined behavior from some tests. Same pattern as the unitialized_copy tests
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@251804 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -19,13 +19,15 @@
|
|||||||
struct B
|
struct B
|
||||||
{
|
{
|
||||||
static int count_;
|
static int count_;
|
||||||
|
static int population_;
|
||||||
int data_;
|
int data_;
|
||||||
explicit B() : data_(1) {}
|
explicit B() : data_(1) { ++population_; }
|
||||||
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
|
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_; ++population_; }
|
||||||
~B() {data_ = 0;}
|
~B() {data_ = 0; --population_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
int B::count_ = 0;
|
int B::count_ = 0;
|
||||||
|
int B::population_ = 0;
|
||||||
|
|
||||||
struct Nasty
|
struct Nasty
|
||||||
{
|
{
|
||||||
@@ -43,6 +45,7 @@ int main()
|
|||||||
const int N = 5;
|
const int N = 5;
|
||||||
char pool[sizeof(B)*N] = {0};
|
char pool[sizeof(B)*N] = {0};
|
||||||
B* bp = (B*)pool;
|
B* bp = (B*)pool;
|
||||||
|
assert(B::population_ == 0);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::uninitialized_fill_n(bp, 5, B());
|
std::uninitialized_fill_n(bp, 5, B());
|
||||||
@@ -50,14 +53,14 @@ int main()
|
|||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < N; ++i)
|
assert(B::population_ == 0);
|
||||||
assert(bp[i].data_ == 0);
|
|
||||||
}
|
}
|
||||||
B::count_ = 0;
|
B::count_ = 0;
|
||||||
B* r = std::uninitialized_fill_n(bp, 2, B());
|
B* r = std::uninitialized_fill_n(bp, 2, B());
|
||||||
assert(r == bp + 2);
|
assert(r == bp + 2);
|
||||||
for (int i = 0; i < 2; ++i)
|
for (int i = 0; i < 2; ++i)
|
||||||
assert(bp[i].data_ == 1);
|
assert(bp[i].data_ == 1);
|
||||||
|
assert(B::population_ == 2);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
@@ -20,13 +20,15 @@
|
|||||||
struct B
|
struct B
|
||||||
{
|
{
|
||||||
static int count_;
|
static int count_;
|
||||||
|
static int population_;
|
||||||
int data_;
|
int data_;
|
||||||
explicit B() : data_(1) {}
|
explicit B() : data_(1) { ++population_; }
|
||||||
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
|
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_; ++population_; }
|
||||||
~B() {data_ = 0;}
|
~B() {data_ = 0; --population_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
int B::count_ = 0;
|
int B::count_ = 0;
|
||||||
|
int B::population_ = 0;
|
||||||
|
|
||||||
struct Nasty
|
struct Nasty
|
||||||
{
|
{
|
||||||
@@ -44,6 +46,7 @@ int main()
|
|||||||
const int N = 5;
|
const int N = 5;
|
||||||
char pool[sizeof(B)*N] = {0};
|
char pool[sizeof(B)*N] = {0};
|
||||||
B* bp = (B*)pool;
|
B* bp = (B*)pool;
|
||||||
|
assert(B::population_ == 0);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::uninitialized_fill(bp, bp+N, B());
|
std::uninitialized_fill(bp, bp+N, B());
|
||||||
@@ -51,13 +54,13 @@ int main()
|
|||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < N; ++i)
|
assert(B::population_ == 0);
|
||||||
assert(bp[i].data_ == 0);
|
|
||||||
}
|
}
|
||||||
B::count_ = 0;
|
B::count_ = 0;
|
||||||
std::uninitialized_fill(bp, bp+2, B());
|
std::uninitialized_fill(bp, bp+2, B());
|
||||||
for (int i = 0; i < 2; ++i)
|
for (int i = 0; i < 2; ++i)
|
||||||
assert(bp[i].data_ == 1);
|
assert(bp[i].data_ == 1);
|
||||||
|
assert(B::population_ == 2);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const int N = 5;
|
const int N = 5;
|
||||||
|
Reference in New Issue
Block a user