Anders Carlsson | d3fd6ba | 2009-05-31 21:53:59 +0000 | [diff] [blame] | 1 | // RUN: clang-cc %s -emit-llvm -o %t && |
Anders Carlsson | ed4e367 | 2009-05-31 20:21:44 +0000 | [diff] [blame] | 2 | |
3 | void t1() { | ||||
4 | int* a = new int; | ||||
5 | } | ||||
Anders Carlsson | d958389 | 2009-05-31 20:26:12 +0000 | [diff] [blame] | 6 | |
7 | // Placement. | ||||
8 | void* operator new(unsigned long, void*) throw(); | ||||
9 | |||||
10 | void t2(int* a) { | ||||
11 | int* b = new (a) int; | ||||
12 | } | ||||
Anders Carlsson | 6d0ffad | 2009-05-31 20:56:36 +0000 | [diff] [blame] | 13 | |
Anders Carlsson | 627a3e5 | 2009-05-31 21:12:26 +0000 | [diff] [blame] | 14 | struct S { |
15 | int a; | ||||
16 | }; | ||||
17 | |||||
Anders Carlsson | d3fd6ba | 2009-05-31 21:53:59 +0000 | [diff] [blame] | 18 | // POD types. |
Anders Carlsson | 6d0ffad | 2009-05-31 20:56:36 +0000 | [diff] [blame] | 19 | void t3() { |
20 | int *a = new int(10); | ||||
Anders Carlsson | 3923e95 | 2009-05-31 21:07:58 +0000 | [diff] [blame] | 21 | _Complex int* b = new _Complex int(10i); |
22 | |||||
Anders Carlsson | 627a3e5 | 2009-05-31 21:12:26 +0000 | [diff] [blame] | 23 | S s; |
24 | s.a = 10; | ||||
25 | S *sp = new S(s); | ||||
Anders Carlsson | 6d0ffad | 2009-05-31 20:56:36 +0000 | [diff] [blame] | 26 | } |
Anders Carlsson | d3fd6ba | 2009-05-31 21:53:59 +0000 | [diff] [blame] | 27 | |
28 | // Non-POD | ||||
29 | struct T { | ||||
30 | T(); | ||||
31 | int a; | ||||
32 | }; | ||||
33 | |||||
34 | void t4() { | ||||
35 | // RUN: grep "call void @_ZN1TC1Ev" %t | count 1 && | ||||
36 | T *t = new T; | ||||
37 | } | ||||
38 | |||||
39 | struct T2 { | ||||
40 | int a; | ||||
41 | T2(int, int); | ||||
42 | }; | ||||
43 | |||||
44 | void t5() { | ||||
45 | // RUN: grep "call void @_ZN2T2C1Eii" %t | count 1 | ||||
46 | T2 *t2 = new T2(10, 10); | ||||
47 | } | ||||
Anders Carlsson | f110853 | 2009-06-01 00:05:16 +0000 | [diff] [blame^] | 48 | |
49 | int *t6() { | ||||
50 | // Null check. | ||||
51 | return new (0) int(10); | ||||
52 | } |