12561885fSEric Fiselier //===----------------------------------------------------------------------===//
22561885fSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
62561885fSEric Fiselier //
72561885fSEric Fiselier //===----------------------------------------------------------------------===//
82561885fSEric Fiselier 
9*31cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11
102561885fSEric Fiselier #include <memory>
112561885fSEric Fiselier #include <string>
122561885fSEric Fiselier #include <cassert>
132561885fSEric Fiselier 
147fc6a556SMarshall Clow #include "test_macros.h"
157fc6a556SMarshall Clow 
162561885fSEric Fiselier //    The only way to create an unique_ptr<T[]> is to default construct them.
172561885fSEric Fiselier 
182561885fSEric Fiselier class foo {
192561885fSEric Fiselier public:
foo()202561885fSEric Fiselier     foo () : val_(3) {}
get() const212561885fSEric Fiselier     int get () const { return val_; }
222561885fSEric Fiselier private:
232561885fSEric Fiselier     int val_;
242561885fSEric Fiselier     };
252561885fSEric Fiselier 
main(int,char **)262df59c50SJF Bastien int main(int, char**)
272561885fSEric Fiselier {
282561885fSEric Fiselier     {
292561885fSEric Fiselier     auto p1 = std::make_unique<int[]>(5);
302561885fSEric Fiselier     for ( int i = 0; i < 5; ++i )
312561885fSEric Fiselier         assert ( p1[i] == 0 );
322561885fSEric Fiselier     }
332561885fSEric Fiselier 
342561885fSEric Fiselier     {
352561885fSEric Fiselier     auto p2 = std::make_unique<std::string[]>(5);
362561885fSEric Fiselier     for ( int i = 0; i < 5; ++i )
372561885fSEric Fiselier         assert ( p2[i].size () == 0 );
382561885fSEric Fiselier     }
392561885fSEric Fiselier 
402561885fSEric Fiselier     {
412561885fSEric Fiselier     auto p3 = std::make_unique<foo[]>(7);
422561885fSEric Fiselier     for ( int i = 0; i < 7; ++i )
432561885fSEric Fiselier         assert ( p3[i].get () == 3 );
442561885fSEric Fiselier     }
452df59c50SJF Bastien 
462df59c50SJF Bastien   return 0;
472561885fSEric Fiselier }
48