build/clang-plugin/tests/TestMustOverride.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/build/clang-plugin/tests/TestMustOverride.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,63 @@
     1.4 +#define MOZ_MUST_OVERRIDE __attribute__((annotate("moz_must_override")))
     1.5 +// Ignore warnings not related to static analysis here
     1.6 +#pragma GCC diagnostic ignored "-Woverloaded-virtual"
     1.7 +
     1.8 +struct S {
     1.9 +  virtual void f() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
    1.10 +  virtual void g() MOZ_MUST_OVERRIDE;
    1.11 +  virtual void h() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
    1.12 +};
    1.13 +struct C : S { // expected-error {{'C' must override 'f'}} expected-error {{'C' must override 'h'}}
    1.14 +  virtual void g() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
    1.15 +  virtual void h(int);
    1.16 +  void q() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
    1.17 +};
    1.18 +struct D : C { // expected-error {{'D' must override 'g'}} expected-error {{'D' must override 'q'}}
    1.19 +  virtual void f();
    1.20 +};
    1.21 +
    1.22 +struct Base {
    1.23 +  virtual void VirtMethod() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
    1.24 +  void NonVirtMethod() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
    1.25 +  static void StaticMethod() MOZ_MUST_OVERRIDE;
    1.26 +};
    1.27 +
    1.28 +struct DoesNotPropagate : Base {
    1.29 +  virtual void VirtMethod();
    1.30 +  void NonVirtMethod();
    1.31 +  static void StaticMethod();
    1.32 +};
    1.33 +
    1.34 +struct Final : DoesNotPropagate { };
    1.35 +
    1.36 +struct Propagates : Base {
    1.37 +  virtual void VirtMethod() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
    1.38 +  void NonVirtMethod() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
    1.39 +  static void StaticMethod() MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
    1.40 +};
    1.41 +
    1.42 +struct FailsFinal : Propagates { }; // expected-error {{'FailsFinal' must override 'VirtMethod'}} expected-error {{'FailsFinal' must override 'NonVirtMethod'}} expected-error {{'FailsFinal' must override 'StaticMethod'}}
    1.43 +
    1.44 +struct WrongOverload : Base { // expected-error {{'WrongOverload' must override 'VirtMethod'}} expected-error {{'WrongOverload' must override 'NonVirtMethod'}}
    1.45 +  virtual void VirtMethod() const;
    1.46 +  void NonVirtMethod(int param);
    1.47 +  static void StaticMethod();
    1.48 +};
    1.49 +
    1.50 +namespace A { namespace B { namespace C {
    1.51 +  struct Param {};
    1.52 +  struct Base {
    1.53 +    void f(Param p) MOZ_MUST_OVERRIDE; // expected-note {{function to override is here}}
    1.54 +  };
    1.55 +}}}
    1.56 +
    1.57 +struct Param {};
    1.58 +
    1.59 +struct Derived : A::B::C::Base {
    1.60 +  typedef A::B::C::Param Typedef;
    1.61 +  void f(Typedef t);
    1.62 +};
    1.63 +
    1.64 +struct BadDerived : A::B::C::Base { // expected-error {{'BadDerived' must override 'f'}}
    1.65 +  void f(Param p);
    1.66 +};

mercurial