build/clang-plugin/tests/TestMustOverride.cpp

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:7641a4ef8bac
1 #define MOZ_MUST_OVERRIDE __attribute__((annotate("moz_must_override")))
2 // Ignore warnings not related to static analysis here
3 #pragma GCC diagnostic ignored "-Woverloaded-virtual"
4
5 struct S {
6 virtual void f() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
7 virtual void g() MOZ_MUST_OVERRIDE;
8 virtual void h() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
9 };
10 struct C : S { // expected-error {{'C' must override 'f'}} expected-error {{'C' must override 'h'}}
11 virtual void g() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
12 virtual void h(int);
13 void q() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
14 };
15 struct D : C { // expected-error {{'D' must override 'g'}} expected-error {{'D' must override 'q'}}
16 virtual void f();
17 };
18
19 struct Base {
20 virtual void VirtMethod() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
21 void NonVirtMethod() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
22 static void StaticMethod() MOZ_MUST_OVERRIDE;
23 };
24
25 struct DoesNotPropagate : Base {
26 virtual void VirtMethod();
27 void NonVirtMethod();
28 static void StaticMethod();
29 };
30
31 struct Final : DoesNotPropagate { };
32
33 struct Propagates : Base {
34 virtual void VirtMethod() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
35 void NonVirtMethod() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
36 static void StaticMethod() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
37 };
38
39 struct FailsFinal : Propagates { }; // expected-error {{'FailsFinal' must override 'VirtMethod'}} expected-error {{'FailsFinal' must override 'NonVirtMethod'}} expected-error {{'FailsFinal' must override 'StaticMethod'}}
40
41 struct WrongOverload : Base { // expected-error {{'WrongOverload' must override 'VirtMethod'}} expected-error {{'WrongOverload' must override 'NonVirtMethod'}}
42 virtual void VirtMethod() const;
43 void NonVirtMethod(int param);
44 static void StaticMethod();
45 };
46
47 namespace A { namespace B { namespace C {
48 struct Param {};
49 struct Base {
50 void f(Param p) MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
51 };
52 }}}
53
54 struct Param {};
55
56 struct Derived : A::B::C::Base {
57 typedef A::B::C::Param Typedef;
58 void f(Typedef t);
59 };
60
61 struct BadDerived : A::B::C::Base { // expected-error {{'BadDerived' must override 'f'}}
62 void f(Param p);
63 };

mercurial