File tree 2 files changed +46
-1
lines changed
2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -3277,6 +3277,8 @@ bool Compiler<Emitter>::VisitCXXInheritedCtorInitExpr(
3277
3277
return this ->emitCall (F, 0 , E);
3278
3278
}
3279
3279
3280
+ // FIXME: This function has become rather unwieldy, especially
3281
+ // the part where we initialize an array allocation of dynamic size.
3280
3282
template <class Emitter >
3281
3283
bool Compiler<Emitter>::VisitCXXNewExpr(const CXXNewExpr *E) {
3282
3284
assert (classifyPrim (E->getType ()) == PT_Ptr);
@@ -3457,7 +3459,16 @@ bool Compiler<Emitter>::VisitCXXNewExpr(const CXXNewExpr *E) {
3457
3459
if (!this ->emitArrayElemPtr (SizeT, E))
3458
3460
return false ;
3459
3461
3460
- if (DynamicInit) {
3462
+ if (isa_and_nonnull<ImplicitValueInitExpr>(DynamicInit) &&
3463
+ DynamicInit->getType ()->isArrayType ()) {
3464
+ QualType ElemType =
3465
+ DynamicInit->getType ()->getAsArrayTypeUnsafe ()->getElementType ();
3466
+ PrimType InitT = classifyPrim (ElemType);
3467
+ if (!this ->visitZeroInitializer (InitT, ElemType, E))
3468
+ return false ;
3469
+ if (!this ->emitStorePop (InitT, E))
3470
+ return false ;
3471
+ } else if (DynamicInit) {
3461
3472
if (std::optional<PrimType> InitT = classify (DynamicInit)) {
3462
3473
if (!this ->visit (DynamicInit))
3463
3474
return false ;
Original file line number Diff line number Diff line change
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());
You can’t perform that action at this time.
0 commit comments