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++98, c++03, c++11
10 #include <memory>
11 #include <string>
12 #include <cassert>
13 
14 //    The only way to create an unique_ptr<T[]> is to default construct them.
15 
16 class foo {
17 public:
18     foo () : val_(3) {}
19     int get () const { return val_; }
20 private:
21     int val_;
22     };
23 
24 int main(int, char**)
25 {
26     {
27     auto p1 = std::make_unique<int[]>(5);
28     for ( int i = 0; i < 5; ++i )
29         assert ( p1[i] == 0 );
30     }
31 
32     {
33     auto p2 = std::make_unique<std::string[]>(5);
34     for ( int i = 0; i < 5; ++i )
35         assert ( p2[i].size () == 0 );
36     }
37 
38     {
39     auto p3 = std::make_unique<foo[]>(7);
40     for ( int i = 0; i < 7; ++i )
41         assert ( p3[i].get () == 3 );
42     }
43 
44   return 0;
45 }
46