1 // RUN: %clang_cc1 %s -fsyntax-only -verify -triple %itanium_abi_triple -Wweak-vtables
2 //
3 // Check that this warning is disabled on MS ABI targets which don't have key
4 // functions.
5 // RUN: %clang_cc1 %s -fsyntax-only -triple %ms_abi_triple -Werror -Wweak-vtables
6 //
7 // -Wweak-template-vtables is deprecated but we still parse it.
8 // RUN: %clang_cc1 %s -fsyntax-only -Werror -Wweak-template-vtables
9
10 struct A { // expected-warning {{'A' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit}}
fA11 virtual void f() { }
12 };
13
14 template<typename T> struct B {
fB15 virtual void f() { }
16 };
17
18 namespace {
19 struct C {
f__anonb27ad9e60111::C20 virtual void f() { }
21 };
22 }
23
f()24 void f() {
25 struct A {
26 virtual void f() { }
27 };
28
29 A a;
30 }
31
32 // Use the vtables
uses_abc()33 void uses_abc() {
34 A a;
35 B<int> b;
36 C c;
37 }
38
39 // <rdar://problem/9979458>
40 class Parent {
41 public:
Parent()42 Parent() {}
43 virtual ~Parent();
44 virtual void * getFoo() const = 0;
45 };
46
47 class Derived : public Parent {
48 public:
49 Derived();
50 void * getFoo() const;
51 };
52
53 class VeryDerived : public Derived { // expected-warning{{'VeryDerived' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit}}
54 public:
getFoo() const55 void * getFoo() const { return 0; }
56 };
57
~Parent()58 Parent::~Parent() {}
59
uses_derived()60 void uses_derived() {
61 Derived d;
62 VeryDerived vd;
63 }
64
65 template<typename T> struct TemplVirt {
66 virtual void f();
67 };
68
69 template class TemplVirt<float>;
70
71 template<> struct TemplVirt<bool> {
72 virtual void f();
73 };
74
75 template<> struct TemplVirt<long> { // expected-warning{{'TemplVirt<long>' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit}}
fTemplVirt76 virtual void f() {}
77 };
78
uses_templ()79 void uses_templ() {
80 TemplVirt<float> f;
81 TemplVirt<bool> b;
82 TemplVirt<long> l;
83 }
84