1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <memory>
11 
12 // template <class ForwardIterator, class Size, class T>
13 //   ForwardIterator
14 //   uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
15 
16 #include <memory>
17 #include <cassert>
18 
19 struct B
20 {
21     static int count_;
22     int data_;
BB23     explicit B() : data_(1) {}
BB24     B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
~BB25     ~B() {data_ = 0;}
26 };
27 
28 int B::count_ = 0;
29 
main()30 int main()
31 {
32     const int N = 5;
33     char pool[sizeof(B)*N] = {0};
34     B* bp = (B*)pool;
35     try
36     {
37         std::uninitialized_fill_n(bp, 5, B());
38         assert(false);
39     }
40     catch (...)
41     {
42         for (int i = 0; i < N; ++i)
43             assert(bp[i].data_ == 0);
44     }
45     B::count_ = 0;
46     B* r = std::uninitialized_fill_n(bp, 2, B());
47     assert(r == bp + 2);
48     for (int i = 0; i < 2; ++i)
49         assert(bp[i].data_ == 1);
50 }
51