Clang Project

clang_source_code/test/SemaCXX/virtual-member-functions-key-function.cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4
5struct A {
6  virtual ~A();
7#if __cplusplus >= 201103L
8// expected-note@-2 2 {{overridden virtual function is here}}
9#endif
10};
11
12struct B : A {
13#if __cplusplus <= 199711L
14// expected-error@-2 {{no suitable member 'operator delete' in 'B'}}
15#else
16// expected-error@-4 {{deleted function '~B' cannot override a non-deleted function}}
17// expected-note@-5  {{virtual destructor requires an unambiguous, accessible 'operator delete'}}
18#endif
19  B() { }
20#if __cplusplus <= 199711L
21// expected-note@-2 {{implicit destructor for 'B' first required here}}
22#endif
23
24  void operator delete(void *, int);
25#if __cplusplus <= 199711L
26// expected-note@-2 {{'operator delete' declared here}}
27#endif
28}; 
29
30struct C : A {
31#if __cplusplus <= 199711L
32// expected-error@-2 {{no suitable member 'operator delete' in 'C'}}
33#else
34// expected-error@-4 {{deleted function '~C' cannot override a non-deleted function}}
35// expected-note@-5  {{virtual destructor requires an unambiguous, accessible 'operator delete'}}
36#endif
37  void operator delete(void *, int);
38#if __cplusplus <= 199711L
39// expected-note@-2 {{'operator delete' declared here}}
40#endif
41}; 
42
43void f() {
44  (void)new B; 
45  (void)new C;
46#if __cplusplus <= 199711L
47// expected-note@-2 {{implicit destructor for 'C' first required here}}
48#endif
49}
50
51// Make sure that the key-function computation is consistent when the
52// first virtual member function of a nested class has an inline body.
53struct Outer {
54  struct Inner {
55    virtual void f() { }
56    void g();
57  };
58};
59
60void Outer::Inner::g() { }
61