| 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 |
TEST_CONSTEXPR_CXX23 bool test() { |
| 17 |
{ |
| 18 |
std::unique_ptr<int> p1 = std::make_unique<int>(1); |
| 19 |
assert(*p1 == 1); |
| 20 |
p1 = std::make_unique<int>(); |
| 21 |
assert(*p1 == 0); |
| 22 |
} |
| 23 |
|
| 24 |
{ |
| 25 |
std::unique_ptr<std::string> p2 = std::make_unique<std::string>("Meow!"); |
| 26 |
assert(*p2 == "Meow!"); |
| 27 |
p2 = std::make_unique<std::string>(); |
| 28 |
assert(*p2 == ""); |
| 29 |
p2 = std::make_unique<std::string>(6, 'z'); |
| 30 |
assert(*p2 == "zzzzzz"); |
| 31 |
} |
| 32 |
|
| 33 |
return true; |
| 34 |
} |
| 35 |
|
| 36 |
int main(int, char**) { |
| 37 |
test(); |
| 38 |
#if TEST_STD_VER >= 23 |
| 39 |
static_assert(test()); |
| 40 |
#endif |
| 41 |
|
| 42 |
return 0; |
| 43 |
} |