Skip to content

Commit a4c9d01

Browse files
committed
[Clang][Sema] placement new initializes typedef array with correct size
1 parent ca0560d commit a4c9d01

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

clang/lib/Sema/TreeTransform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12731,7 +12731,7 @@ TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
1273112731
}
1273212732

1273312733
QualType AllocType = AllocTypeInfo->getType();
12734-
if (!ArraySize) {
12734+
if (ArraySize) {
1273512735
// If no array size was specified, but the new expression was
1273612736
// instantiated with an array type (e.g., "new T" where T is
1273712737
// instantiated with "int[4]"), extract the outer bound from the
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clang++ -S -emit-llvm -o - %s | FileCheck %s
2+
#include <new>
3+
4+
// CHECK: call void @llvm.memset.p0.i64(ptr align 1 %x, i8 0, i64 8, i1 false)
5+
// CHECK: call void @llvm.memset.p0.i64(ptr align 16 %x, i8 0, i64 32, i1 false)
6+
template <typename TYPE>
7+
void f()
8+
{
9+
typedef TYPE TArray[8];
10+
11+
TArray x;
12+
new(&x) TArray();
13+
}
14+
15+
int main()
16+
{
17+
f<char>();
18+
f<int>();
19+
}

0 commit comments

Comments
 (0)