summaryrefslogtreecommitdiffstats
path: root/build/clang-plugin/tests/TestMustOverride.cpp
blob: 8e053f6c2321db15615749564eefff67aca1e477 (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
#define MOZ_MUST_OVERRIDE __attribute__((annotate("moz_must_override")))
// Ignore warnings not related to static analysis here
#pragma GCC diagnostic ignored "-Woverloaded-virtual"

struct S {
  virtual void f() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
  virtual void g() MOZ_MUST_OVERRIDE;
  virtual void h() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
};
struct C : S { // expected-error {{'C' must override 'f'}} expected-error {{'C' must override 'h'}}
  virtual void g() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
  virtual void h(int);
  void q() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
};
struct D : C { // expected-error {{'D' must override 'g'}} expected-error {{'D' must override 'q'}}
  virtual void f();
};

struct Base {
  virtual void VirtMethod() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
  void NonVirtMethod() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
  static void StaticMethod() MOZ_MUST_OVERRIDE;
};

struct DoesNotPropagate : Base {
  virtual void VirtMethod();
  void NonVirtMethod();
  static void StaticMethod();
};

struct Final : DoesNotPropagate { };

struct Propagates : Base {
  virtual void VirtMethod() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
  void NonVirtMethod() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
  static void StaticMethod() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
};

struct FailsFinal : Propagates { }; // expected-error {{'FailsFinal' must override 'VirtMethod'}} expected-error {{'FailsFinal' must override 'NonVirtMethod'}} expected-error {{'FailsFinal' must override 'StaticMethod'}}

struct WrongOverload : Base { // expected-error {{'WrongOverload' must override 'VirtMethod'}} expected-error {{'WrongOverload' must override 'NonVirtMethod'}}
  virtual void VirtMethod() const;
  void NonVirtMethod(int param);
  static void StaticMethod();
};

namespace A { namespace B { namespace C {
  struct Param {};
  struct Base {
    void f(Param p) MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
  };
}}}

struct Param {};

struct Derived : A::B::C::Base {
  typedef A::B::C::Param Typedef;
  void f(Typedef t);
};

struct BadDerived : A::B::C::Base { // expected-error {{'BadDerived' must override 'f'}}
  void f(Param p);
};