blob: 89c33474bf4caf584db4dcf43ceee9326154478f [file] [log] [blame]
Douglas Gregora9aafbe2008-11-25 04:08:05 +00001// RUN: clang -fsyntax-only -verify %s
2
Sebastian Redlb5ee8742008-12-03 20:26:15 +00003#include <stddef.h>
4
Sebastian Redl19fec9d2008-11-21 19:14:01 +00005struct S // expected-note {{candidate}}
6{
7 S(int, int, double); // expected-note {{candidate}}
8 S(double, int); // expected-note {{candidate}} expected-note {{candidate}}
9 S(float, int); // expected-note {{candidate}} expected-note {{candidate}}
10};
11struct T;
12
Sebastian Redlb5ee8742008-12-03 20:26:15 +000013void* operator new(size_t); // expected-note {{candidate}}
14void* operator new(size_t, int*); // expected-note {{candidate}}
15void* operator new(size_t, float*); // expected-note {{candidate}}
16
Sebastian Redl19fec9d2008-11-21 19:14:01 +000017void good_news()
18{
19 int *pi = new int;
20 float *pf = new (pi) float();
21 pi = new int(1);
22 pi = new int('c');
23 const int *pci = new const int();
24 S *ps = new S(1, 2, 3.4);
Sebastian Redl66df3ef2008-12-02 14:43:59 +000025 ps = new (pf) (S)(1, 2, 3.4);
Sebastian Redl19fec9d2008-11-21 19:14:01 +000026 S *(*paps)[2] = new S*[*pi][2];
27 ps = new (S[3])(1, 2, 3.4);
28 typedef int ia4[4];
29 ia4 *pai = new (int[3][4]);
Sebastian Redl7c5955a2008-12-02 16:35:44 +000030 pi = ::new int;
Sebastian Redl19fec9d2008-11-21 19:14:01 +000031}
32
Douglas Gregora9aafbe2008-11-25 04:08:05 +000033void bad_news(int *ip)
Sebastian Redl19fec9d2008-11-21 19:14:01 +000034{
35 int i = 1;
36 (void)new; // expected-error {{missing type specifier}}
37 (void)new 4; // expected-error {{missing type specifier}}
38 (void)new () int; // expected-error {{expected expression}}
Sebastian Redl66df3ef2008-12-02 14:43:59 +000039 (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 +000040 (void)new int[1][i]; // expected-error {{only the first dimension}}
41 (void)new (int[1][i]); // expected-error {{only the first dimension}}
42 (void)new int(*(S*)0); // expected-error {{incompatible type initializing}}
43 (void)new int(1, 2); // expected-error {{initializer of a builtin type can only take one argument}}
44 (void)new S(1); // expected-error {{no matching constructor}}
Douglas Gregora9aafbe2008-11-25 04:08:05 +000045 (void)new S(1, 1); // expected-error {{call to constructor of 'S' is ambiguous}}
Sebastian Redl19fec9d2008-11-21 19:14:01 +000046 (void)new const int; // expected-error {{must provide an initializer}}
Douglas Gregora9aafbe2008-11-25 04:08:05 +000047 (void)new float*(ip); // expected-error {{incompatible type initializing 'int *', expected 'float *'}}
Sebastian Redl66df3ef2008-12-02 14:43:59 +000048 // Undefined, but clang should reject it directly.
49 (void)new int[-1]; // expected-error {{array size is negative}}
50 (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 +000051 (void)::S::new int; // expected-error {{expected unqualified-id}}
Sebastian Redlb5ee8742008-12-03 20:26:15 +000052 (void)new (0, 0) int; // expected-error {{no matching function for call to 'operator new'}}
Sebastian Redl19fec9d2008-11-21 19:14:01 +000053 // Some lacking cases due to lack of sema support.
54}
55
56void good_deletes()
57{
58 delete (int*)0;
59 delete [](int*)0;
60 delete (S*)0;
Sebastian Redl7c5955a2008-12-02 16:35:44 +000061 ::delete (int*)0;
Sebastian Redl19fec9d2008-11-21 19:14:01 +000062}
63
64void bad_deletes()
65{
66 delete 0; // expected-error {{cannot delete expression of type 'int'}}
67 delete [0] (int*)0; // expected-error {{expected ']'}} \
Chris Lattner921342c2008-11-23 23:17:07 +000068 // expected-note {{to match this '['}}
Sebastian Redl19fec9d2008-11-21 19:14:01 +000069 delete (void*)0; // expected-error {{cannot delete expression}}
70 delete (T*)0; // expected-warning {{deleting pointer to incomplete type}}
Sebastian Redl7c5955a2008-12-02 16:35:44 +000071 ::S::delete (int*)0; // expected-error {{expected unqualified-id}}
Sebastian Redl19fec9d2008-11-21 19:14:01 +000072}