2008-11-25 07:08:05 +03:00
|
|
|
// RUN: clang -fsyntax-only -verify %s
|
|
|
|
|
2008-11-21 22:14:01 +03:00
|
|
|
struct S // expected-note {{candidate}}
|
|
|
|
{
|
|
|
|
S(int, int, double); // expected-note {{candidate}}
|
|
|
|
S(double, int); // expected-note {{candidate}} expected-note {{candidate}}
|
|
|
|
S(float, int); // expected-note {{candidate}} expected-note {{candidate}}
|
|
|
|
};
|
|
|
|
struct T;
|
|
|
|
|
|
|
|
void good_news()
|
|
|
|
{
|
|
|
|
int *pi = new int;
|
|
|
|
float *pf = new (pi) float();
|
|
|
|
pi = new int(1);
|
|
|
|
pi = new int('c');
|
|
|
|
const int *pci = new const int();
|
|
|
|
S *ps = new S(1, 2, 3.4);
|
2008-12-02 17:43:59 +03:00
|
|
|
ps = new (pf) (S)(1, 2, 3.4);
|
2008-11-21 22:14:01 +03:00
|
|
|
S *(*paps)[2] = new S*[*pi][2];
|
|
|
|
ps = new (S[3])(1, 2, 3.4);
|
|
|
|
typedef int ia4[4];
|
|
|
|
ia4 *pai = new (int[3][4]);
|
2008-12-02 19:35:44 +03:00
|
|
|
pi = ::new int;
|
2008-11-21 22:14:01 +03:00
|
|
|
}
|
|
|
|
|
2008-11-25 07:08:05 +03:00
|
|
|
void bad_news(int *ip)
|
2008-11-21 22:14:01 +03:00
|
|
|
{
|
|
|
|
int i = 1;
|
|
|
|
(void)new; // expected-error {{missing type specifier}}
|
|
|
|
(void)new 4; // expected-error {{missing type specifier}}
|
|
|
|
(void)new () int; // expected-error {{expected expression}}
|
2008-12-02 17:43:59 +03:00
|
|
|
(void)new int[1.1]; // expected-error {{array size expression must have integral or enumerated type, not 'double'}}
|
2008-11-21 22:14:01 +03:00
|
|
|
(void)new int[1][i]; // expected-error {{only the first dimension}}
|
|
|
|
(void)new (int[1][i]); // expected-error {{only the first dimension}}
|
|
|
|
(void)new int(*(S*)0); // expected-error {{incompatible type initializing}}
|
|
|
|
(void)new int(1, 2); // expected-error {{initializer of a builtin type can only take one argument}}
|
|
|
|
(void)new S(1); // expected-error {{no matching constructor}}
|
2008-11-25 07:08:05 +03:00
|
|
|
(void)new S(1, 1); // expected-error {{call to constructor of 'S' is ambiguous}}
|
2008-11-21 22:14:01 +03:00
|
|
|
(void)new const int; // expected-error {{must provide an initializer}}
|
2008-11-25 07:08:05 +03:00
|
|
|
(void)new float*(ip); // expected-error {{incompatible type initializing 'int *', expected 'float *'}}
|
2008-12-02 17:43:59 +03:00
|
|
|
// Undefined, but clang should reject it directly.
|
|
|
|
(void)new int[-1]; // expected-error {{array size is negative}}
|
|
|
|
(void)new int[*(S*)0]; // expected-error {{array size expression must have integral or enumerated type, not 'struct S'}}
|
2008-12-02 19:35:44 +03:00
|
|
|
(void)::S::new int; // expected-error {{expected unqualified-id}}
|
2008-11-21 22:14:01 +03:00
|
|
|
// Some lacking cases due to lack of sema support.
|
|
|
|
}
|
|
|
|
|
|
|
|
void good_deletes()
|
|
|
|
{
|
|
|
|
delete (int*)0;
|
|
|
|
delete [](int*)0;
|
|
|
|
delete (S*)0;
|
2008-12-02 19:35:44 +03:00
|
|
|
::delete (int*)0;
|
2008-11-21 22:14:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void bad_deletes()
|
|
|
|
{
|
|
|
|
delete 0; // expected-error {{cannot delete expression of type 'int'}}
|
|
|
|
delete [0] (int*)0; // expected-error {{expected ']'}} \
|
2008-11-24 02:17:07 +03:00
|
|
|
// expected-note {{to match this '['}}
|
2008-11-21 22:14:01 +03:00
|
|
|
delete (void*)0; // expected-error {{cannot delete expression}}
|
|
|
|
delete (T*)0; // expected-warning {{deleting pointer to incomplete type}}
|
2008-12-02 19:35:44 +03:00
|
|
|
::S::delete (int*)0; // expected-error {{expected unqualified-id}}
|
2008-11-21 22:14:01 +03:00
|
|
|
}
|