Douglas Gregor | a9aafbe | 2008-11-25 04:08:05 +0000 | [diff] [blame] | 1 | // RUN: clang -fsyntax-only -verify %s |
| 2 | |
Sebastian Redl | 19fec9d | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 3 | struct S // expected-note {{candidate}} |
| 4 | { |
| 5 | S(int, int, double); // expected-note {{candidate}} |
| 6 | S(double, int); // expected-note {{candidate}} expected-note {{candidate}} |
| 7 | S(float, int); // expected-note {{candidate}} expected-note {{candidate}} |
| 8 | }; |
| 9 | struct T; |
| 10 | |
| 11 | void good_news() |
| 12 | { |
| 13 | int *pi = new int; |
| 14 | float *pf = new (pi) float(); |
| 15 | pi = new int(1); |
| 16 | pi = new int('c'); |
| 17 | const int *pci = new const int(); |
| 18 | S *ps = new S(1, 2, 3.4); |
Sebastian Redl | 66df3ef | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 19 | ps = new (pf) (S)(1, 2, 3.4); |
Sebastian Redl | 19fec9d | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 20 | S *(*paps)[2] = new S*[*pi][2]; |
| 21 | ps = new (S[3])(1, 2, 3.4); |
| 22 | typedef int ia4[4]; |
| 23 | ia4 *pai = new (int[3][4]); |
| 24 | } |
| 25 | |
Douglas Gregor | a9aafbe | 2008-11-25 04:08:05 +0000 | [diff] [blame] | 26 | void bad_news(int *ip) |
Sebastian Redl | 19fec9d | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 27 | { |
| 28 | int i = 1; |
| 29 | (void)new; // expected-error {{missing type specifier}} |
| 30 | (void)new 4; // expected-error {{missing type specifier}} |
| 31 | (void)new () int; // expected-error {{expected expression}} |
Sebastian Redl | 66df3ef | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 32 | (void)new int[1.1]; // expected-error {{array size expression must have integral or enumerated type, not 'double'}} |
Sebastian Redl | 19fec9d | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 33 | (void)new int[1][i]; // expected-error {{only the first dimension}} |
| 34 | (void)new (int[1][i]); // expected-error {{only the first dimension}} |
| 35 | (void)new int(*(S*)0); // expected-error {{incompatible type initializing}} |
| 36 | (void)new int(1, 2); // expected-error {{initializer of a builtin type can only take one argument}} |
| 37 | (void)new S(1); // expected-error {{no matching constructor}} |
Douglas Gregor | a9aafbe | 2008-11-25 04:08:05 +0000 | [diff] [blame] | 38 | (void)new S(1, 1); // expected-error {{call to constructor of 'S' is ambiguous}} |
Sebastian Redl | 19fec9d | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 39 | (void)new const int; // expected-error {{must provide an initializer}} |
Douglas Gregor | a9aafbe | 2008-11-25 04:08:05 +0000 | [diff] [blame] | 40 | (void)new float*(ip); // expected-error {{incompatible type initializing 'int *', expected 'float *'}} |
Sebastian Redl | 66df3ef | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 41 | // Undefined, but clang should reject it directly. |
| 42 | (void)new int[-1]; // expected-error {{array size is negative}} |
| 43 | (void)new int[*(S*)0]; // expected-error {{array size expression must have integral or enumerated type, not 'struct S'}} |
Sebastian Redl | 19fec9d | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 44 | // Some lacking cases due to lack of sema support. |
| 45 | } |
| 46 | |
| 47 | void good_deletes() |
| 48 | { |
| 49 | delete (int*)0; |
| 50 | delete [](int*)0; |
| 51 | delete (S*)0; |
| 52 | } |
| 53 | |
| 54 | void bad_deletes() |
| 55 | { |
| 56 | delete 0; // expected-error {{cannot delete expression of type 'int'}} |
| 57 | delete [0] (int*)0; // expected-error {{expected ']'}} \ |
Chris Lattner | 921342c | 2008-11-23 23:17:07 +0000 | [diff] [blame] | 58 | // expected-note {{to match this '['}} |
Sebastian Redl | 19fec9d | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 59 | delete (void*)0; // expected-error {{cannot delete expression}} |
| 60 | delete (T*)0; // expected-warning {{deleting pointer to incomplete type}} |
| 61 | } |