35 lines · cpp
1// RUN: %clang_cc1 -std=c++2c -fexperimental-new-constant-interpreter -verify=expected,both %s2// RUN: %clang_cc1 -std=c++2c -verify=ref,both %s3 4/// This used to cause problems because the heap-allocated array5/// is initialized by an ImplicitValueInitExpr of incomplete array type.6 7inline namespace {8template < class _Tp >9using __add_lvalue_reference_t = __add_lvalue_reference(_Tp);10template < class _Tp > using __remove_extent_t = __remove_extent(_Tp);11}12inline namespace {13template < class > class unique_ptr;14template < class _Tp > struct unique_ptr< _Tp[] > {15_Tp *__ptr_;16 17template <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 }};25constexpr unique_ptr< int[] > make_unique(decltype(sizeof(int)) __n) {26 return unique_ptr< int[] >(int(), new __remove_extent_t< int>[__n](), __n);27}}28 29constexpr bool test() {30 auto p1 = make_unique(5);31 (p1[0] == 0); // both-warning {{expression result unused}}32 return true;33}34static_assert(test());35