Clang Project

clang_source_code/test/SemaCXX/warn-weak-vtables.cpp
1// RUN: %clang_cc1 %s -fsyntax-only -verify -triple %itanium_abi_triple -Wweak-vtables -Wweak-template-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 -Wweak-template-vtables
6
7struct A { // expected-warning {{'A' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit}}
8  virtual void f() { } 
9};
10
11template<typename T> struct B {
12  virtual void f() { } 
13};
14
15namespace {
16  struct C { 
17    virtual void f() { }
18  };
19}
20
21void f() {
22  struct A {
23    virtual void f() { }
24  };
25
26  A a;
27}
28
29// Use the vtables
30void uses_abc() {
31  A a;
32  B<int> b;
33  C c;
34}
35
36// <rdar://problem/9979458>
37class Parent {
38public:
39  Parent() {}
40  virtual ~Parent();
41  virtual void * getFoo() const = 0;    
42};
43  
44class Derived : public Parent {
45public:
46  Derived();
47  void * getFoo() const;
48};
49
50class VeryDerived : public Derived { // expected-warning{{'VeryDerived' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit}}
51public:
52  void * getFoo() const { return 0; }
53};
54
55Parent::~Parent() {}
56
57void uses_derived() {
58  Derived d;
59  VeryDerived vd;
60}
61
62template<typename T> struct TemplVirt {
63  virtual void f();
64};
65
66template class TemplVirt<float>; // expected-warning{{explicit template instantiation 'TemplVirt<float>' will emit a vtable in every translation unit}}
67
68template<> struct TemplVirt<bool> {
69  virtual void f();
70};
71
72template<> struct TemplVirt<long> { // expected-warning{{'TemplVirt<long>' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit}}
73  virtual void f() {}
74};
75
76void uses_templ() {
77  TemplVirt<float> f;
78  TemplVirt<bool> b;
79  TemplVirt<long> l;
80}
81