diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2015-11-02 15:25:53 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2015-11-02 15:25:53 +0000 |
commit | 8eb1d544f89e6015743ddacfc86bbf06fffdb935 (patch) | |
tree | 833c34f04594ef7723447bcd6e8fa62798850726 /libcxx/test/std/utilities/memory | |
parent | 7c1f36a6b7503d1aa5d5e696fb1fe78628cab5d2 (diff) | |
download | bcm5719-llvm-8eb1d544f89e6015743ddacfc86bbf06fffdb935.tar.gz bcm5719-llvm-8eb1d544f89e6015743ddacfc86bbf06fffdb935.zip |
Remove undefined behavior from some tests. Thanks to Walter Brown for the heads-up.
llvm-svn: 251802
Diffstat (limited to 'libcxx/test/std/utilities/memory')
2 files changed, 18 insertions, 10 deletions
diff --git a/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp b/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp index f431335db73..dcf34ac4782 100644 --- a/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp +++ b/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp @@ -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}; diff --git a/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp b/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp index 3b2007b969c..69e39423fc0 100644 --- a/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp +++ b/libcxx/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp @@ -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}; |