xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/devirtualize-vtable-marking.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1 // RUN: %clang_cc1 -verify -std=c++11 %s
2 
3 template <typename T> struct OwnPtr {
4   T *p;
~OwnPtrOwnPtr5   ~OwnPtr() {
6     // expected-error@+1 {{invalid application of 'sizeof'}}
7     static_assert(sizeof(T) > 0, "incomplete T");
8     delete p;
9   }
10 };
11 
12 namespace use_vtable_for_vcall {
13 struct Incomplete; // expected-note {{forward declaration}}
14 struct A {
~Ause_vtable_for_vcall::A15   virtual ~A() {}
muse_vtable_for_vcall::A16   virtual void m() {}
17 };
18 struct B : A { // expected-note {{in instantiation}}
19   B();
muse_vtable_for_vcall::B20   virtual void m() { }
m2use_vtable_for_vcall::B21   virtual void m2() { static_cast<A *>(this)->m(); }
22   OwnPtr<Incomplete> m_sqlError;
23 };
24 
f()25 B *f() {
26   return new B();
27 }
28 }
29 
30 namespace dont_mark_qualified_vcall {
31 struct Incomplete;
32 struct A {
~Adont_mark_qualified_vcall::A33   virtual ~A() {}
mdont_mark_qualified_vcall::A34   virtual void m() {}
35 };
36 struct B : A {
37   B();
38   // Previously we would mark B's vtable referenced to devirtualize this call to
39   // A::m, even though it's not a virtual call.
mdont_mark_qualified_vcall::B40   virtual void m() { A::m(); }
41   OwnPtr<Incomplete> m_sqlError;
42 };
43 
f()44 B *f() {
45   return new B();
46 }
47 }
48