blob: 1ff1b2ecb5b650053df8815b236e86dec68b3653 [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);
19 ps = new (pf) S(1, 2, 3.4);
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 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}}
32 (void)new int[1.1]; // expected-error {{size of array has non-integer type}}
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 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 Redl19fec9d2008-11-21 19:14:01 +000041 // Some lacking cases due to lack of sema support.
42}
43
44void good_deletes()
45{
46 delete (int*)0;
47 delete [](int*)0;
48 delete (S*)0;
49}
50
51void bad_deletes()
52{
53 delete 0; // expected-error {{cannot delete expression of type 'int'}}
54 delete [0] (int*)0; // expected-error {{expected ']'}} \
Chris Lattner921342c2008-11-23 23:17:07 +000055 // expected-note {{to match this '['}}
Sebastian Redl19fec9d2008-11-21 19:14:01 +000056 delete (void*)0; // expected-error {{cannot delete expression}}
57 delete (T*)0; // expected-warning {{deleting pointer to incomplete type}}
58}