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__anone1f199090111::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 class Parent {
40 public:
Parent()41 Parent() {}
42 virtual ~Parent();
43 virtual void * getFoo() const = 0;
44 };
45
46 class Derived : public Parent {
47 public:
48 Derived();
49 void * getFoo() const;
50 };
51
52 class VeryDerived : public Derived { // expected-warning{{'VeryDerived' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit}}
53 public:
getFoo() const54 void * getFoo() const { return 0; }
55 };
56
~Parent()57 Parent::~Parent() {}
58
uses_derived()59 void uses_derived() {
60 Derived d;
61 VeryDerived vd;
62 }
63
64 template<typename T> struct TemplVirt {
65 virtual void f();
66 };
67
68 template class TemplVirt<float>;
69
70 template<> struct TemplVirt<bool> {
71 virtual void f();
72 };
73
74 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}}
fTemplVirt75 virtual void f() {}
76 };
77
uses_templ()78 void uses_templ() {
79 TemplVirt<float> f;
80 TemplVirt<bool> b;
81 TemplVirt<long> l;
82 }
83