blob: d30665387153144e925c5eac72271841a410ca48 [file] [log] [blame]
Stephen Hines651f13c2014-04-23 16:59:28 -07001// RUN: %clang_cc1 %s -fsyntax-only -verify -triple %itanium_abi_triple -Wweak-vtables -Wweak-template-vtables
2// RUN: %clang_cc1 %s -fsyntax-only -triple %ms_abi_triple -Werror -Wno-weak-vtables -Wno-weak-template-vtables
Anders Carlsson1610b812010-02-06 02:27:10 +00003
4struct A { // expected-warning {{'A' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit}}
5 virtual void f() { }
6};
7
8template<typename T> struct B {
9 virtual void f() { }
10};
11
12namespace {
13 struct C {
14 virtual void f() { }
15 };
16}
17
18void f() {
19 struct A {
20 virtual void f() { }
21 };
Douglas Gregor6fb745b2010-05-13 16:44:06 +000022
Stephen Hines0e2c34f2015-03-23 12:09:02 -070023 A a;
Douglas Gregor6fb745b2010-05-13 16:44:06 +000024}
25
26// Use the vtables
Stephen Hines0e2c34f2015-03-23 12:09:02 -070027void uses_abc() {
28 A a;
29 B<int> b;
30 C c;
Chris Lattner83e7a782010-04-07 22:58:06 +000031}
Douglas Gregora120d012011-09-23 19:04:03 +000032
33// <rdar://problem/9979458>
34class Parent {
35public:
36 Parent() {}
37 virtual ~Parent();
38 virtual void * getFoo() const = 0;
39};
40
41class Derived : public Parent {
42public:
43 Derived();
44 void * getFoo() const;
45};
46
47class VeryDerived : public Derived { // expected-warning{{'VeryDerived' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit}}
48public:
49 void * getFoo() const { return 0; }
50};
51
52Parent::~Parent() {}
53
Stephen Hines0e2c34f2015-03-23 12:09:02 -070054void uses_derived() {
55 Derived d;
56 VeryDerived vd;
Douglas Gregora120d012011-09-23 19:04:03 +000057}
David Blaikie44d95b52011-12-09 18:32:50 +000058
59template<typename T> struct TemplVirt {
60 virtual void f();
61};
62
63template class TemplVirt<float>; // expected-warning{{explicit template instantiation 'TemplVirt<float>' will emit a vtable in every translation unit}}
64
65template<> struct TemplVirt<bool> {
66 virtual void f();
67};
68
69template<> struct TemplVirt<long> { // expected-warning{{'TemplVirt<long>' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit}}
70 virtual void f() {}
71};
72
Stephen Hines0e2c34f2015-03-23 12:09:02 -070073void uses_templ() {
74 TemplVirt<float> f;
75 TemplVirt<bool> b;
76 TemplVirt<long> l;
David Blaikie44d95b52011-12-09 18:32:50 +000077}