[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / warn-weak-vtables.cpp
blobe5207775f000bf3141a0039e5126d0620a13d41f
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
10 struct A { // expected-warning {{'A' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit}}
11 virtual void f() { }
14 template<typename T> struct B {
15 virtual void f() { }
18 namespace {
19 struct C {
20 virtual void f() { }
24 void f() {
25 struct A {
26 virtual void f() { }
29 A a;
32 // Use the vtables
33 void uses_abc() {
34 A a;
35 B<int> b;
36 C c;
39 class Parent {
40 public:
41 Parent() {}
42 virtual ~Parent();
43 virtual void * getFoo() const = 0;
46 class Derived : public Parent {
47 public:
48 Derived();
49 void * getFoo() const;
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:
54 void * getFoo() const { return 0; }
57 Parent::~Parent() {}
59 void uses_derived() {
60 Derived d;
61 VeryDerived vd;
64 template<typename T> struct TemplVirt {
65 virtual void f();
68 template class TemplVirt<float>;
70 template<> struct TemplVirt<bool> {
71 virtual void f();
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}}
75 virtual void f() {}
78 void uses_templ() {
79 TemplVirt<float> f;
80 TemplVirt<bool> b;
81 TemplVirt<long> l;