summaryrefslogtreecommitdiffstats
path: root/build/clang-plugin/tests/TestNeedsNoVTableType.cpp
blob: 531a1c82a16f610a1f8bbfb6357f5c927217b8df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#define MOZ_NEEDS_NO_VTABLE_TYPE __attribute__((annotate("moz_needs_no_vtable_type")))

template <class T>
struct MOZ_NEEDS_NO_VTABLE_TYPE PickyConsumer { // expected-error {{'PickyConsumer<B>' cannot be instantiated because 'B' has a VTable}} expected-error {{'PickyConsumer<E>' cannot be instantiated because 'E' has a VTable}} expected-error {{'PickyConsumer<F>' cannot be instantiated because 'F' has a VTable}} expected-error {{'PickyConsumer<G>' cannot be instantiated because 'G' has a VTable}}
  T *m;
};

template <class T>
struct MOZ_NEEDS_NO_VTABLE_TYPE PickyConsumer_A { // expected-error {{'PickyConsumer_A<B>' cannot be instantiated because 'B' has a VTable}} expected-error {{'PickyConsumer_A<E>' cannot be instantiated because 'E' has a VTable}} expected-error {{'PickyConsumer_A<F>' cannot be instantiated because 'F' has a VTable}} expected-error {{'PickyConsumer_A<G>' cannot be instantiated because 'G' has a VTable}}
  T *m;
};
template <class T>
struct PickyConsumerWrapper {
  PickyConsumer_A<T> m; // expected-note {{bad instantiation of 'PickyConsumer_A<B>' requested here}} expected-note {{bad instantiation of 'PickyConsumer_A<E>' requested here}} expected-note {{bad instantiation of 'PickyConsumer_A<F>' requested here}} expected-note {{bad instantiation of 'PickyConsumer_A<G>' requested here}}
};

template <class T>
struct MOZ_NEEDS_NO_VTABLE_TYPE PickyConsumer_B { // expected-error {{'PickyConsumer_B<B>' cannot be instantiated because 'B' has a VTable}} expected-error {{'PickyConsumer_B<E>' cannot be instantiated because 'E' has a VTable}} expected-error {{'PickyConsumer_B<F>' cannot be instantiated because 'F' has a VTable}} expected-error {{'PickyConsumer_B<G>' cannot be instantiated because 'G' has a VTable}}
  T *m;
};
template <class T>
struct PickyConsumerSubclass : PickyConsumer_B<T> {}; // expected-note {{bad instantiation of 'PickyConsumer_B<B>' requested here}} expected-note {{bad instantiation of 'PickyConsumer_B<E>' requested here}} expected-note {{bad instantiation of 'PickyConsumer_B<F>' requested here}} expected-note {{bad instantiation of 'PickyConsumer_B<G>' requested here}}

template <class T>
struct NonPickyConsumer {
  T *m;
};

struct A {};
struct B : virtual A {};
struct C : A {};
struct D {
  void d();
};
struct E {
  virtual void e();
};
struct F : E {
  virtual void e() final;
};
struct G {
  virtual void e() = 0;
};

void f() {
  {
    PickyConsumer<A> a1;
    PickyConsumerWrapper<A> a2;
    PickyConsumerSubclass<A> a3;
    NonPickyConsumer<A> a4;
  }

  {
    PickyConsumer<B> a1; // expected-note {{bad instantiation of 'PickyConsumer<B>' requested here}}
    PickyConsumerWrapper<B> a2;
    PickyConsumerSubclass<B> a3;
    NonPickyConsumer<B> a4;
  }

  {
    PickyConsumer<C> a1;
    PickyConsumerWrapper<C> a2;
    PickyConsumerSubclass<C> a3;
    NonPickyConsumer<C> a4;
  }

  {
    PickyConsumer<D> a1;
    PickyConsumerWrapper<D> a2;
    PickyConsumerSubclass<D> a3;
    NonPickyConsumer<D> a4;
  }

  {
    PickyConsumer<E> a1; // expected-note {{bad instantiation of 'PickyConsumer<E>' requested here}}
    PickyConsumerWrapper<E> a2;
    PickyConsumerSubclass<E> a3;
    NonPickyConsumer<E> a4;
  }

  {
    PickyConsumer<F> a1; // expected-note {{bad instantiation of 'PickyConsumer<F>' requested here}}
    PickyConsumerWrapper<F> a2;
    PickyConsumerSubclass<F> a3;
    NonPickyConsumer<F> a4;
  }

  {
    PickyConsumer<G> a1; // expected-note {{bad instantiation of 'PickyConsumer<G>' requested here}}
    PickyConsumerWrapper<G> a2;
    PickyConsumerSubclass<G> a3;
    NonPickyConsumer<G> a4;
  }
}