| 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 |
TEST_CONSTEXPR_CXX23 foo() : val_(3) {} |
| 21 |
TEST_CONSTEXPR_CXX23 int get() const { return val_; } |
| 22 |
|
| 23 |
private: |
| 24 |
int val_; |
| 25 |
}; |
| 26 |
|
| 27 |
TEST_CONSTEXPR_CXX23 bool test() { |
| 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 true; |
| 47 |
} |
| 48 |
|
| 49 |
int main(int, char**) { |
| 50 |
test(); |
| 51 |
#if TEST_STD_VER >= 23 |
| 52 |
static_assert(test()); |
| 53 |
#endif |
| 54 |
|
| 55 |
return 0; |
| 56 |
} |