summaryrefslogtreecommitdiff
path: root/test/CXX/special/class.dtor/p9.cpp
blob: 4c6fbf43437a139fc50e30be2f92035b01ff853a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// RUN: %clang_cc1 -fsyntax-only -triple %itanium_abi_triple -verify -std=c++98 %s
// RUN: %clang_cc1 -fsyntax-only -triple %ms_abi_triple -DMSABI -verify -std=c++98 %s
// RUN: %clang_cc1 -fsyntax-only -triple %itanium_abi_triple -verify -std=c++11 %s
// RUN: %clang_cc1 -fsyntax-only -triple %ms_abi_triple -DMSABI -verify -std=c++11 %s

typedef __typeof(sizeof(int)) size_t;

// PR7803
namespace test0 {
  class A {
  public:
    static void operator delete(void *p) {};
    virtual ~A();
  };

  class B : protected A {
  public:
    ~B();
  };

  class C : protected B {
  public:
    using B::operator delete;
    ~C();
  };

  // Shouldn't have an error.
  C::~C() {}
}

namespace test1 {
  class A {
  public:
    static void operator delete(void *p) {};
    virtual ~A();
  };

  class B : protected A {
  public:
    static void operator delete(void *, size_t) {};
    ~B();
  };

  class C : protected B {
  public:
    using A::operator delete;
    using B::operator delete;

    ~C();
  };

  // We assume that the intent is to treat C::operator delete(void*, size_t) as
  // /not/ being a usual deallocation function, as it would be if it were
  // declared with in C directly.
  C::~C() {}

  struct D {
    void operator delete(void*); // expected-note {{member 'operator delete' declared here}}
    void operator delete(void*, ...); // expected-note {{member 'operator delete' declared here}}
    virtual ~D();
  };
  // FIXME: The standard doesn't say this is ill-formed, but presumably either
  // it should be or the variadic operator delete should not be a usual
  // deallocation function.
  D::~D() {} // expected-error {{multiple suitable 'operator delete' functions in 'D'}}
}

// ...at the point of definition of a virtual destructor...
namespace test2 {
  struct A {
    virtual ~A();
    static void operator delete(void*, const int &);
  };

  struct B {
    virtual ~B();
    static void operator delete(void*, const int &); // expected-note {{declared here}}
  };
  B::~B() {} // expected-error {{no suitable member 'operator delete' in 'B'}}

#if __cplusplus < 201103L
  struct CBase { virtual ~CBase(); };
  struct C : CBase { // expected-error {{no suitable member 'operator delete' in 'C'}}
    static void operator delete(void*, const int &); // expected-note {{declared here}}
  };
  void test() {
    C c; // expected-note {{first required here}}
  }
#else
  struct CBase { virtual ~CBase(); }; // expected-note {{overridden virtual function is here}}
  struct C : CBase { // expected-error {{deleted function '~C' cannot override a non-deleted function}} expected-note {{requires an unambiguous, accessible 'operator delete'}}
    static void operator delete(void*, const int &);
  };
  void test() {
    C c; // expected-error {{attempt to use a deleted function}}
  }
#endif
}

// PR7346
namespace test3 {
  struct A {
#ifdef MSABI
    // expected-error@+2 {{no suitable member 'operator delete' in 'A'}}
#endif
    virtual ~A();
#ifdef MSABI
    // expected-note@+2 {{declared here}}
#endif
    static void operator delete(void*, const int &);
  };

  struct B : A {
    virtual ~B() {}
    static void operator delete(void*);
  };

  void f() {
#ifdef MSABI
    // expected-note@+2 {{implicit default constructor for 'test3::B' first required here}}
#endif
    B use_vtable;
  }
}