1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11
10 #include <memory>
11 #include <string>
12 #include <cassert>
13 
14 #include "test_macros.h"
15 
16 //    The only way to create an unique_ptr<T[]> is to default construct them.
17 
18 class foo {
19 public:
20     foo () : val_(3) {}
21     int get () const { return val_; }
22 private:
23     int val_;
24     };
25 
26 int main(int, char**)
27 {
28     {
29     auto p1 = std::make_unique<int[]>(5);
30     for ( int i = 0; i < 5; ++i )
31         assert ( p1[i] == 0 );
32     }
33 
34     {
35     auto p2 = std::make_unique<std::string[]>(5);
36     for ( int i = 0; i < 5; ++i )
37         assert ( p2[i].size () == 0 );
38     }
39 
40     {
41     auto p3 = std::make_unique<foo[]>(7);
42     for ( int i = 0; i < 7; ++i )
43         assert ( p3[i].get () == 3 );
44     }
45 
46   return 0;
47 }
48