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