Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1 | // 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 Carlsson | 1610b81 | 2010-02-06 02:27:10 +0000 | [diff] [blame] | 3 | |
| 4 | struct 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 | |
| 8 | template<typename T> struct B { |
| 9 | virtual void f() { } |
| 10 | }; |
| 11 | |
| 12 | namespace { |
| 13 | struct C { |
| 14 | virtual void f() { } |
| 15 | }; |
| 16 | } |
| 17 | |
| 18 | void f() { |
| 19 | struct A { |
| 20 | virtual void f() { } |
| 21 | }; |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 22 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 23 | A a; |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | // Use the vtables |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 27 | void uses_abc() { |
| 28 | A a; |
| 29 | B<int> b; |
| 30 | C c; |
Chris Lattner | 83e7a78 | 2010-04-07 22:58:06 +0000 | [diff] [blame] | 31 | } |
Douglas Gregor | a120d01 | 2011-09-23 19:04:03 +0000 | [diff] [blame] | 32 | |
| 33 | // <rdar://problem/9979458> |
| 34 | class Parent { |
| 35 | public: |
| 36 | Parent() {} |
| 37 | virtual ~Parent(); |
| 38 | virtual void * getFoo() const = 0; |
| 39 | }; |
| 40 | |
| 41 | class Derived : public Parent { |
| 42 | public: |
| 43 | Derived(); |
| 44 | void * getFoo() const; |
| 45 | }; |
| 46 | |
| 47 | class VeryDerived : public Derived { // expected-warning{{'VeryDerived' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit}} |
| 48 | public: |
| 49 | void * getFoo() const { return 0; } |
| 50 | }; |
| 51 | |
| 52 | Parent::~Parent() {} |
| 53 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 54 | void uses_derived() { |
| 55 | Derived d; |
| 56 | VeryDerived vd; |
Douglas Gregor | a120d01 | 2011-09-23 19:04:03 +0000 | [diff] [blame] | 57 | } |
David Blaikie | 44d95b5 | 2011-12-09 18:32:50 +0000 | [diff] [blame] | 58 | |
| 59 | template<typename T> struct TemplVirt { |
| 60 | virtual void f(); |
| 61 | }; |
| 62 | |
| 63 | template class TemplVirt<float>; // expected-warning{{explicit template instantiation 'TemplVirt<float>' will emit a vtable in every translation unit}} |
| 64 | |
| 65 | template<> struct TemplVirt<bool> { |
| 66 | virtual void f(); |
| 67 | }; |
| 68 | |
| 69 | 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}} |
| 70 | virtual void f() {} |
| 71 | }; |
| 72 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 73 | void uses_templ() { |
| 74 | TemplVirt<float> f; |
| 75 | TemplVirt<bool> b; |
| 76 | TemplVirt<long> l; |
David Blaikie | 44d95b5 | 2011-12-09 18:32:50 +0000 | [diff] [blame] | 77 | } |