blob: d9b471362f61f69be46ecbce90a62eeef01ac59a [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]);
Sebastian Redl7c5955a2008-12-02 16:35:44 +000024 pi = ::new int;
Sebastian Redl19fec9d2008-11-21 19:14:01 +000025}
26
Douglas Gregora9aafbe2008-11-25 04:08:05 +000027void bad_news(int *ip)
Sebastian Redl19fec9d2008-11-21 19:14:01 +000028{
29 int i = 1;
30 (void)new; // expected-error {{missing type specifier}}
31 (void)new 4; // expected-error {{missing type specifier}}
32 (void)new () int; // expected-error {{expected expression}}
Sebastian Redl66df3ef2008-12-02 14:43:59 +000033 (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 +000034 (void)new int[1][i]; // expected-error {{only the first dimension}}
35 (void)new (int[1][i]); // expected-error {{only the first dimension}}
36 (void)new int(*(S*)0); // expected-error {{incompatible type initializing}}
37 (void)new int(1, 2); // expected-error {{initializer of a builtin type can only take one argument}}
38 (void)new S(1); // expected-error {{no matching constructor}}
Douglas Gregora9aafbe2008-11-25 04:08:05 +000039 (void)new S(1, 1); // expected-error {{call to constructor of 'S' is ambiguous}}
Sebastian Redl19fec9d2008-11-21 19:14:01 +000040 (void)new const int; // expected-error {{must provide an initializer}}
Douglas Gregora9aafbe2008-11-25 04:08:05 +000041 (void)new float*(ip); // expected-error {{incompatible type initializing 'int *', expected 'float *'}}
Sebastian Redl66df3ef2008-12-02 14:43:59 +000042 // Undefined, but clang should reject it directly.
43 (void)new int[-1]; // expected-error {{array size is negative}}
44 (void)new int[*(S*)0]; // expected-error {{array size expression must have integral or enumerated type, not 'struct S'}}
Sebastian Redl7c5955a2008-12-02 16:35:44 +000045 (void)::S::new int; // expected-error {{expected unqualified-id}}
Sebastian Redl19fec9d2008-11-21 19:14:01 +000046 // Some lacking cases due to lack of sema support.
47}
48
49void good_deletes()
50{
51 delete (int*)0;
52 delete [](int*)0;
53 delete (S*)0;
Sebastian Redl7c5955a2008-12-02 16:35:44 +000054 ::delete (int*)0;
Sebastian Redl19fec9d2008-11-21 19:14:01 +000055}
56
57void bad_deletes()
58{
59 delete 0; // expected-error {{cannot delete expression of type 'int'}}
60 delete [0] (int*)0; // expected-error {{expected ']'}} \
Chris Lattner921342c2008-11-23 23:17:07 +000061 // expected-note {{to match this '['}}
Sebastian Redl19fec9d2008-11-21 19:14:01 +000062 delete (void*)0; // expected-error {{cannot delete expression}}
63 delete (T*)0; // expected-warning {{deleting pointer to incomplete type}}
Sebastian Redl7c5955a2008-12-02 16:35:44 +000064 ::S::delete (int*)0; // expected-error {{expected unqualified-id}}
Sebastian Redl19fec9d2008-11-21 19:14:01 +000065}