[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / clang / test / CXX / class.derived / class.virtual / p3-0x.cpp
blob41a5954bf8638e83009017759c4bfdc411e350d1
1 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
3 namespace Test1 {
5 struct B {
6 virtual void f(int);
7 };
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;
15 namespace Test2 {
17 struct A {
18 virtual void f(int, char, int);
21 template<typename T>
22 struct B : A {
23 // FIXME: Diagnose this.
24 virtual void f(T) override;
27 template<typename T>
28 struct C : A {
29 virtual void f(int) override; // expected-error {{does not override}}
34 namespace Test3 {
36 struct A {
37 virtual void f(int, char, int);
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}}
45 template struct B<int, char, int>;
46 template struct B<int>; // expected-note {{in instantiation of template class 'Test3::B<int>' requested here}}
50 namespace Test4 {
51 struct B {
52 virtual void f() const final; // expected-note {{overridden virtual function is here}}
55 struct D : B {
56 void f() const; // expected-error {{declaration of 'f' overrides a 'final' function}}
61 namespace PR13499 {
62 struct X {
63 virtual void f();
64 virtual void h();
66 template<typename T> struct A : X {
67 void f() override;
68 void h() final;
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'}}
74 B<int> b; // no-note
75 template<typename T> struct C : T {
76 void g() override;
77 void i() final;
79 template<typename T> struct D : X {
80 virtual void g() override; // expected-error {{does not override}}
81 virtual void i() final;
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'}}
89 // FIXME: Diagnose these in the template definition, not in the instantiation.
90 E<> e; // expected-note {{in instantiation of}}
92 template<typename T> struct Y : T {
93 void f() override;
94 void h() final;
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'}}
100 Y<X> y;
101 Z<X> z; // expected-note {{in instantiation of}}
104 namespace MemberOfUnknownSpecialization {
105 template<typename T> struct A {
106 struct B {};
107 struct C : B {
108 void f() override;
112 template<> struct A<int>::B {
113 virtual void f();
115 // ok
116 A<int>::C c1;
118 template<> struct A<char>::B {
119 void f();
121 // expected-error@-13 {{only virtual member functions can be marked 'override'}}
122 // expected-note@+1 {{in instantiation of}}
123 A<char>::C c2;
125 template<> struct A<double>::B {
126 virtual void f() final;
128 // expected-error@-20 {{declaration of 'f' overrides a 'final' function}}
129 // expected-note@-3 {{here}}
130 // expected-note@+1 {{in instantiation of}}
131 A<double>::C c3;
134 namespace DiagnosticsQOI {
135 struct X {
136 virtual ~X();
137 virtual void foo(int x); // expected-note {{hidden overloaded virtual function}}
138 virtual void bar(int x); // expected-note 2 {{hidden overloaded virtual function}}
139 virtual void bar(float x); // expected-note 2 {{hidden overloaded virtual function}}
142 struct Y : X {
143 void foo(int x, int y) override; // expected-error {{non-virtual member function marked 'override' hides virtual member function}}
144 void bar(double) override; // expected-error {{non-virtual member function marked 'override' hides virtual member functions}}
145 void bar(long double) final; // expected-error {{non-virtual member function marked 'final' hides virtual member functions}}
148 template<typename T>
149 struct Z : T {
150 static void foo() override; // expected-error {{only virtual member functions can be marked 'override'}}