p19.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // RUN: %clang_cc1 -fsyntax-only -verify -fexceptions %s
  2. typedef __SIZE_TYPE__ size_t;
  3. // Operator delete template for placement new with global lookup
  4. template<int I>
  5. struct X0 {
  6. X0();
  7. static void* operator new(size_t) {
  8. return I; // expected-error{{cannot initialize}}
  9. }
  10. static void operator delete(void*) {
  11. int *ip = I; // expected-error{{cannot initialize}}
  12. }
  13. };
  14. void test_X0() {
  15. // Using the global operator new suppresses the search for a
  16. // operator delete in the class.
  17. ::new X0<2>;
  18. new X0<3>; // expected-note 2{{instantiation}}
  19. }
  20. // Operator delete template for placement new[] with global lookup
  21. template<int I>
  22. struct X1 {
  23. X1();
  24. static void* operator new[](size_t) {
  25. return I; // expected-error{{cannot initialize}}
  26. }
  27. static void operator delete[](void*) {
  28. int *ip = I; // expected-error{{cannot initialize}}
  29. }
  30. };
  31. void test_X1() {
  32. // Using the global operator new suppresses the search for a
  33. // operator delete in the class.
  34. ::new X1<2> [17];
  35. new X1<3> [17]; // expected-note 2{{instantiation}}
  36. }