blob: 0a1a3aed310e52006b69c8470065d564cf9cd4e4 [file] [log] [blame]
Douglas Gregora9aafbe2008-11-25 04:08:05 +00001// RUN: clang -fsyntax-only -verify %s
2
Sebastian Redl19fec9d2008-11-21 19:14:01 +00003struct 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};
9struct T;
10
11void 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 Redl66df3ef2008-12-02 14:43:59 +000019 ps = new (pf) (S)(1, 2, 3.4);
Sebastian Redl19fec9d2008-11-21 19:14:01 +000020 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 Gregora9aafbe2008-11-25 04:08:05 +000026void bad_news(int *ip)
Sebastian Redl19fec9d2008-11-21 19:14:01 +000027{
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 Redl66df3ef2008-12-02 14:43:59 +000032 (void)new int[1.1]; // expected-error {{array size expression must have integral or enumerated type, not 'double'}}
Sebastian Redl19fec9d2008-11-21 19:14:01 +000033 (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 Gregora9aafbe2008-11-25 04:08:05 +000038 (void)new S(1, 1); // expected-error {{call to constructor of 'S' is ambiguous}}
Sebastian Redl19fec9d2008-11-21 19:14:01 +000039 (void)new const int; // expected-error {{must provide an initializer}}
Douglas Gregora9aafbe2008-11-25 04:08:05 +000040 (void)new float*(ip); // expected-error {{incompatible type initializing 'int *', expected 'float *'}}
Sebastian Redl66df3ef2008-12-02 14:43:59 +000041 // 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 Redl19fec9d2008-11-21 19:14:01 +000044 // Some lacking cases due to lack of sema support.
45}
46
47void good_deletes()
48{
49 delete (int*)0;
50 delete [](int*)0;
51 delete (S*)0;
52}
53
54void bad_deletes()
55{
56 delete 0; // expected-error {{cannot delete expression of type 'int'}}
57 delete [0] (int*)0; // expected-error {{expected ']'}} \
Chris Lattner921342c2008-11-23 23:17:07 +000058 // expected-note {{to match this '['}}
Sebastian Redl19fec9d2008-11-21 19:14:01 +000059 delete (void*)0; // expected-error {{cannot delete expression}}
60 delete (T*)0; // expected-warning {{deleting pointer to incomplete type}}
61}