new.cpp revision 6ac5fc49ee70b4e3ce3e242c02c66586f652d7ac
1// RUN: clang-cc %s -emit-llvm -o - | FileCheck %s 2 3void t1() { 4 int* a = new int; 5} 6 7// Placement. 8void* operator new(unsigned long, void*) throw(); 9 10void t2(int* a) { 11 int* b = new (a) int; 12} 13 14struct S { 15 int a; 16}; 17 18// POD types. 19void t3() { 20 int *a = new int(10); 21 _Complex int* b = new _Complex int(10i); 22 23 S s; 24 s.a = 10; 25 S *sp = new S(s); 26} 27 28// Non-POD 29struct T { 30 T(); 31 int a; 32}; 33 34void t4() { 35 // CHECK: call void @_ZN1TC1Ev 36 T *t = new T; 37} 38 39struct T2 { 40 int a; 41 T2(int, int); 42}; 43 44void t5() { 45 // CHECK: call void @_ZN2T2C1Eii 46 T2 *t2 = new T2(10, 10); 47} 48 49int *t6() { 50 // Null check. 51 return new (0) int(10); 52} 53 54void t7() { 55 new int(); 56} 57 58struct U { 59 ~U(); 60}; 61 62void t8(int n) { 63 new int[10]; 64 new int[n]; 65 66 // Non-POD 67 new T[10]; 68 new T[n]; 69 70 // Cookie required 71 new U[10]; 72 new U[n]; 73} 74