reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    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
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s 

namespace Test1 {

struct B {
  virtual void f(int);
};

struct D : B {
  virtual void f(long) override; // expected-error {{'f' marked 'override' but does not override any member functions}}
  void f(int) override;
};
}

namespace Test2 {

struct A {
  virtual void f(int, char, int);
};

template<typename T>
struct B : A {
  // FIXME: Diagnose this.
  virtual void f(T) override;
};

template<typename T>
struct C : A {
  virtual void f(int) override; // expected-error {{does not override}}
};

}

namespace Test3 {

struct A {
  virtual void f(int, char, int);
};

template<typename... Args>
struct B : A { 
  virtual void f(Args...) override; // expected-error {{'f' marked 'override' but does not override any member functions}}
};

template struct B<int, char, int>;
template struct B<int>; // expected-note {{in instantiation of template class 'Test3::B<int>' requested here}}

}

namespace Test4 {
struct B {
  virtual void f() const final; // expected-note {{overridden virtual function is here}}
};

struct D : B {
  void f() const; // expected-error {{declaration of 'f' overrides a 'final' function}}
};

}

namespace PR13499 {
  struct X {
    virtual void f();
    virtual void h();
  };
  template<typename T> struct A : X {
    void f() override;
    void h() final;
  };
  template<typename T> struct B : X {
    void g() override; // expected-error {{only virtual member functions can be marked 'override'}}
    void i() final; // expected-error {{only virtual member functions can be marked 'final'}}
  };
  B<int> b; // no-note
  template<typename T> struct C : T {
    void g() override;
    void i() final;
  };
  template<typename T> struct D : X {
    virtual void g() override; // expected-error {{does not override}}
    virtual void i() final;
  };
  template<typename...T> struct E : X {
    void f(T...) override;
    void g(T...) override; // expected-error {{only virtual member functions can be marked 'override'}}
    void h(T...) final;
    void i(T...) final; // expected-error {{only virtual member functions can be marked 'final'}}
  };
  // FIXME: Diagnose these in the template definition, not in the instantiation.
  E<> e; // expected-note {{in instantiation of}}

  template<typename T> struct Y : T {
    void f() override;
    void h() final;
  };
  template<typename T> struct Z : T {
    void g() override; // expected-error {{only virtual member functions can be marked 'override'}}
    void i() final; // expected-error {{only virtual member functions can be marked 'final'}}
  };
  Y<X> y;
  Z<X> z; // expected-note {{in instantiation of}}
}

namespace MemberOfUnknownSpecialization {
  template<typename T> struct A {
    struct B {};
    struct C : B {
      void f() override;
    };
  };

  template<> struct A<int>::B {
    virtual void f();
  };
  // ok
  A<int>::C c1;

  template<> struct A<char>::B {
    void f();
  };
  // expected-error@-13 {{only virtual member functions can be marked 'override'}}
  // expected-note@+1 {{in instantiation of}}
  A<char>::C c2;

  template<> struct A<double>::B {
    virtual void f() final;
  };
  // expected-error@-20 {{declaration of 'f' overrides a 'final' function}}
  // expected-note@-3 {{here}}
  // expected-note@+1 {{in instantiation of}}
  A<double>::C c3;
}

namespace DiagnosticsQOI {
  struct X {
    virtual ~X();
    virtual void foo(int x); // expected-note {{hidden overloaded virtual function}}
    virtual void bar(int x); // expected-note 2 {{hidden overloaded virtual function}}
    virtual void bar(float x); // expected-note 2 {{hidden overloaded virtual function}}
  };

  struct Y : X {
    void foo(int x, int y) override; // expected-error {{non-virtual member function marked 'override' hides virtual member function}}
    void bar(double) override; // expected-error {{non-virtual member function marked 'override' hides virtual member functions}}
    void bar(long double) final; // expected-error {{non-virtual member function marked 'final' hides virtual member functions}}
  };
  
  template<typename T>
  struct Z : T {
    static void foo() override; // expected-error {{only virtual member functions can be marked 'override'}}
  };
}