• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
2 
3 namespace Test1 {
4 
5 struct B {
6   virtual void f(int);
7 };
8 
9 struct D : B {
10   virtual void f(long) override; // expected-error {{'f' marked 'override' but does not override any member functions}}
11   void f(int) override;
12 };
13 }
14 
15 namespace Test2 {
16 
17 struct A {
18   virtual void f(int, char, int);
19 };
20 
21 template<typename T>
22 struct B : A {
23   // FIXME: Diagnose this.
24   virtual void f(T) override;
25 };
26 
27 template<typename T>
28 struct C : A {
29   virtual void f(int) override; // expected-error {{does not override}}
30 };
31 
32 }
33 
34 namespace Test3 {
35 
36 struct A {
37   virtual void f(int, char, int);
38 };
39 
40 template<typename... Args>
41 struct B : A {
42   virtual void f(Args...) override; // expected-error {{'f' marked 'override' but does not override any member functions}}
43 };
44 
45 template struct B<int, char, int>;
46 template struct B<int>; // expected-note {{in instantiation of template class 'Test3::B<int>' requested here}}
47 
48 }
49 
50 namespace Test4 {
51 struct B {
52   virtual void f() const final; // expected-note {{overridden virtual function is here}}
53 };
54 
55 struct D : B {
56   void f() const; // expected-error {{declaration of 'f' overrides a 'final' function}}
57 };
58 
59 }
60 
61 namespace PR13499 {
62   struct X {
63     virtual void f();
64     virtual void h();
65   };
66   template<typename T> struct A : X {
67     void f() override;
68     void h() final;
69   };
70   template<typename T> struct B : X {
71     void g() override; // expected-error {{only virtual member functions can be marked 'override'}}
72     void i() final; // expected-error {{only virtual member functions can be marked 'final'}}
73   };
74   B<int> b; // no-note
75   template<typename T> struct C : T {
76     void g() override;
77     void i() final;
78   };
79   template<typename T> struct D : X {
80     virtual void g() override; // expected-error {{does not override}}
81     virtual void i() final;
82   };
83   template<typename...T> struct E : X {
84     void f(T...) override;
85     void g(T...) override; // expected-error {{only virtual member functions can be marked 'override'}}
86     void h(T...) final;
87     void i(T...) final; // expected-error {{only virtual member functions can be marked 'final'}}
88   };
89   // FIXME: Diagnose these in the template definition, not in the instantiation.
90   E<> e; // expected-note {{in instantiation of}}
91 
92   template<typename T> struct Y : T {
93     void f() override;
94     void h() final;
95   };
96   template<typename T> struct Z : T {
97     void g() override; // expected-error {{only virtual member functions can be marked 'override'}}
98     void i() final; // expected-error {{only virtual member functions can be marked 'final'}}
99   };
100   Y<X> y;
101   Z<X> z; // expected-note {{in instantiation of}}
102 }
103