153 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s 2 3namespace Test1 {4 5struct B {6 virtual void f(int);7};8 9struct 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 15namespace Test2 {16 17struct A {18 virtual void f(int, char, int);19};20 21template<typename T>22struct B : A {23 // FIXME: Diagnose this.24 virtual void f(T) override;25};26 27template<typename T>28struct C : A {29 virtual void f(int) override; // expected-error {{does not override}}30};31 32}33 34namespace Test3 {35 36struct A {37 virtual void f(int, char, int);38};39 40template<typename... Args>41struct B : A { 42 virtual void f(Args...) override; // expected-error {{'f' marked 'override' but does not override any member functions}}43};44 45template struct B<int, char, int>;46template struct B<int>; // expected-note {{in instantiation of template class 'Test3::B<int>' requested here}}47 48}49 50namespace Test4 {51struct B {52 virtual void f() const final; // expected-note {{overridden virtual function is here}}53};54 55struct D : B {56 void f() const; // expected-error {{declaration of 'f' overrides a 'final' function}}57};58 59}60 61namespace 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-note75 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 104namespace MemberOfUnknownSpecialization {105 template<typename T> struct A {106 struct B {};107 struct C : B {108 void f() override;109 };110 };111 112 template<> struct A<int>::B {113 virtual void f();114 };115 // ok116 A<int>::C c1;117 118 template<> struct A<char>::B {119 void f();120 };121 // expected-error@-13 {{only virtual member functions can be marked 'override'}}122 // expected-note@+1 {{in instantiation of}}123 A<char>::C c2;124 125 template<> struct A<double>::B {126 virtual void f() final;127 };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;132}133 134namespace 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}}140 };141 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}}146 };147 148 template<typename T>149 struct Z : T {150 static void foo() override; // expected-error {{only virtual member functions can be marked 'override'}}151 };152}153