new-delete.cpp revision 4c5d320a7581f4b80b151630c91cea5727fa9923
14c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlstruct S // expected-note {{candidate}} 24c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl{ 34c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl S(int, int, double); // expected-note {{candidate}} 44c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl S(double, int); // expected-note {{candidate}} expected-note {{candidate}} 54c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl S(float, int); // expected-note {{candidate}} expected-note {{candidate}} 64c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl}; 74c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlstruct T; 84c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 94c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlvoid good_news() 104c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl{ 114c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl int *pi = new int; 124c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl float *pf = new (pi) float(); 134c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl pi = new int(1); 144c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl pi = new int('c'); 154c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl const int *pci = new const int(); 164c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl S *ps = new S(1, 2, 3.4); 174c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl ps = new (pf) S(1, 2, 3.4); 184c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl S *(*paps)[2] = new S*[*pi][2]; 194c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl ps = new (S[3])(1, 2, 3.4); 204c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl typedef int ia4[4]; 214c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl ia4 *pai = new (int[3][4]); 224c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl} 234c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 244c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlvoid bad_news() 254c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl{ 264c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl int i = 1; 274c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl (void)new; // expected-error {{missing type specifier}} 284c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl (void)new 4; // expected-error {{missing type specifier}} 294c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl (void)new () int; // expected-error {{expected expression}} 304c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl (void)new int[1.1]; // expected-error {{size of array has non-integer type}} 314c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl (void)new int[1][i]; // expected-error {{only the first dimension}} 324c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl (void)new (int[1][i]); // expected-error {{only the first dimension}} 334c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl (void)new int(*(S*)0); // expected-error {{incompatible type initializing}} 344c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl (void)new int(1, 2); // expected-error {{initializer of a builtin type can only take one argument}} 354c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl (void)new S(1); // expected-error {{no matching constructor}} 364c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl (void)new S(1, 1); // expected-error {{call to constructor of 'struct S' is ambiguous}} 374c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl (void)new const int; // expected-error {{must provide an initializer}} 384c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 394c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // Some lacking cases due to lack of sema support. 404c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl} 414c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 424c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlvoid good_deletes() 434c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl{ 444c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl delete (int*)0; 454c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl delete [](int*)0; 464c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl delete (S*)0; 474c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl} 484c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 494c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redlvoid bad_deletes() 504c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl{ 514c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl delete 0; // expected-error {{cannot delete expression of type 'int'}} 524c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl delete [0] (int*)0; // expected-error {{expected ']'}} \ 534c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // expected-error {{to match this '['}} 544c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl delete (void*)0; // expected-error {{cannot delete expression}} 554c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl delete (T*)0; // expected-warning {{deleting pointer to incomplete type}} 564c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl} 57