Home | History | Annotate | Download | only in SemaCXX
      1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -fcxx-exceptions %s
      2 
      3 int i = delete; // expected-error {{only functions can have deleted definitions}}
      4 
      5 void fn() = delete; // expected-note {{candidate function has been explicitly deleted}}
      6 
      7 void fn2(); // expected-note {{previous declaration is here}}
      8 void fn2() = delete; // expected-error {{deleted definition must be first declaration}}
      9 
     10 void fn3() = delete; // expected-note {{previous definition is here}}
     11 void fn3() { // expected-error {{redefinition}}
     12 }
     13 
     14 void ov(int) {} // expected-note {{candidate function}}
     15 void ov(double) = delete; // expected-note {{candidate function has been explicitly deleted}}
     16 
     17 struct WithDel {
     18   WithDel() = delete; // expected-note {{function has been explicitly marked deleted here}}
     19   void fn() = delete; // expected-note {{function has been explicitly marked deleted here}}
     20   operator int() = delete; // expected-note {{function has been explicitly marked deleted here}}
     21   void operator +(int) = delete;
     22 
     23   int i = delete; // expected-error {{only functions can have deleted definitions}}
     24 };
     25 
     26 void test() {
     27   fn(); // expected-error {{call to deleted function 'fn'}}
     28   ov(1);
     29   ov(1.0); // expected-error {{call to deleted function 'ov'}}
     30 
     31   WithDel dd; // expected-error {{call to deleted constructor of 'WithDel'}}
     32   WithDel *d = 0;
     33   d->fn(); // expected-error {{attempt to use a deleted function}}
     34   int i = *d; // expected-error {{invokes a deleted function}}
     35 }
     36 
     37 struct DelDtor {
     38   ~DelDtor() = delete; // expected-note 9{{here}}
     39 };
     40 void f() {
     41   DelDtor *p = new DelDtor[3]; // expected-error {{attempt to use a deleted function}}
     42   delete [] p; // expected-error {{attempt to use a deleted function}}
     43   const DelDtor &dd2 = DelDtor(); // expected-error {{attempt to use a deleted function}}
     44   DelDtor dd; // expected-error {{attempt to use a deleted function}}
     45   throw dd; // expected-error {{attempt to use a deleted function}}
     46 }
     47 struct X : DelDtor {
     48   ~X() {} // expected-error {{attempt to use a deleted function}}
     49 };
     50 struct Y {
     51   DelDtor dd;
     52   ~Y() {} // expected-error {{attempt to use a deleted function}}
     53 };
     54 struct Z : virtual DelDtor {
     55   ~Z() {} // expected-error {{attempt to use a deleted function}}
     56 };
     57 DelDtor dd; // expected-error {{attempt to use a deleted function}}
     58