Debian Codegraph @

clang/test/AST/ByteCode/libcxx/make_unique.cpp

raw
1 // RUN: %clang_cc1 -std=c++2c -fexperimental-new-constant-interpreter -verify=expected,both %s
2 // RUN: %clang_cc1 -std=c++2c -verify=ref,both %s
3
4 /// This used to cause problems because the heap-allocated array
5 /// is initialized by an ImplicitValueInitExpr of incomplete array type.
6
7 inline namespace {
8 template < class _Tp >
9 using __add_lvalue_reference_t = __add_lvalue_reference(_Tp);
10 template < class _Tp > using __remove_extent_t = __remove_extent(_Tp);
11 }
12 inline namespace {
13 template < class > class unique_ptr;
14 template < class _Tp > struct unique_ptr< _Tp[] > {
15 _Tp *__ptr_;
16
17 template <
18 class _Tag, class _Ptr>
19 constexpr unique_ptr(_Tag, _Ptr __ptr, unsigned) : __ptr_(__ptr){}
20 constexpr ~unique_ptr() { delete[] __ptr_; }
21 constexpr __add_lvalue_reference_t< _Tp >
22 operator[](decltype(sizeof(int)) __i) {
23 return __ptr_[__i];
24 }};
25 constexpr unique_ptr< int[] > make_unique(decltype(sizeof(int)) __n) {
26 return unique_ptr< int[] >(int(), new __remove_extent_t< int>[__n](), __n);
27 }}
28
29 constexpr bool test() {
30 auto p1 = make_unique(5);
31 (p1[0] == 0); // both-warning {{expression result unused}}
32 return true;
33 }
34 static_assert(test());