1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc namespace Test1 { 4*f4a2713aSLionel Sambuc 5*f4a2713aSLionel Sambuc struct B { 6*f4a2713aSLionel Sambuc virtual void f(int); 7*f4a2713aSLionel Sambuc }; 8*f4a2713aSLionel Sambuc 9*f4a2713aSLionel Sambuc struct D : B { 10*f4a2713aSLionel Sambuc virtual void f(long) override; // expected-error {{'f' marked 'override' but does not override any member functions}} 11*f4a2713aSLionel Sambuc void f(int) override; 12*f4a2713aSLionel Sambuc }; 13*f4a2713aSLionel Sambuc } 14*f4a2713aSLionel Sambuc 15*f4a2713aSLionel Sambuc namespace Test2 { 16*f4a2713aSLionel Sambuc 17*f4a2713aSLionel Sambuc struct A { 18*f4a2713aSLionel Sambuc virtual void f(int, char, int); 19*f4a2713aSLionel Sambuc }; 20*f4a2713aSLionel Sambuc 21*f4a2713aSLionel Sambuc template<typename T> 22*f4a2713aSLionel Sambuc struct B : A { 23*f4a2713aSLionel Sambuc // FIXME: Diagnose this. 24*f4a2713aSLionel Sambuc virtual void f(T) override; 25*f4a2713aSLionel Sambuc }; 26*f4a2713aSLionel Sambuc 27*f4a2713aSLionel Sambuc template<typename T> 28*f4a2713aSLionel Sambuc struct C : A { 29*f4a2713aSLionel Sambuc virtual void f(int) override; // expected-error {{does not override}} 30*f4a2713aSLionel Sambuc }; 31*f4a2713aSLionel Sambuc 32*f4a2713aSLionel Sambuc } 33*f4a2713aSLionel Sambuc 34*f4a2713aSLionel Sambuc namespace Test3 { 35*f4a2713aSLionel Sambuc 36*f4a2713aSLionel Sambuc struct A { 37*f4a2713aSLionel Sambuc virtual void f(int, char, int); 38*f4a2713aSLionel Sambuc }; 39*f4a2713aSLionel Sambuc 40*f4a2713aSLionel Sambuc template<typename... Args> 41*f4a2713aSLionel Sambuc struct B : A { 42*f4a2713aSLionel Sambuc virtual void f(Args...) override; // expected-error {{'f' marked 'override' but does not override any member functions}} 43*f4a2713aSLionel Sambuc }; 44*f4a2713aSLionel Sambuc 45*f4a2713aSLionel Sambuc template struct B<int, char, int>; 46*f4a2713aSLionel Sambuc template struct B<int>; // expected-note {{in instantiation of template class 'Test3::B<int>' requested here}} 47*f4a2713aSLionel Sambuc 48*f4a2713aSLionel Sambuc } 49*f4a2713aSLionel Sambuc 50*f4a2713aSLionel Sambuc namespace Test4 { 51*f4a2713aSLionel Sambuc struct B { 52*f4a2713aSLionel Sambuc virtual void f() const final; // expected-note {{overridden virtual function is here}} 53*f4a2713aSLionel Sambuc }; 54*f4a2713aSLionel Sambuc 55*f4a2713aSLionel Sambuc struct D : B { 56*f4a2713aSLionel Sambuc void f() const; // expected-error {{declaration of 'f' overrides a 'final' function}} 57*f4a2713aSLionel Sambuc }; 58*f4a2713aSLionel Sambuc 59*f4a2713aSLionel Sambuc } 60*f4a2713aSLionel Sambuc 61*f4a2713aSLionel Sambuc namespace PR13499 { 62*f4a2713aSLionel Sambuc struct X { 63*f4a2713aSLionel Sambuc virtual void f(); 64*f4a2713aSLionel Sambuc virtual void h(); 65*f4a2713aSLionel Sambuc }; 66*f4a2713aSLionel Sambuc template<typename T> struct A : X { 67*f4a2713aSLionel Sambuc void f() override; 68*f4a2713aSLionel Sambuc void h() final; 69*f4a2713aSLionel Sambuc }; 70*f4a2713aSLionel Sambuc template<typename T> struct B : X { 71*f4a2713aSLionel Sambuc void g() override; // expected-error {{only virtual member functions can be marked 'override'}} 72*f4a2713aSLionel Sambuc void i() final; // expected-error {{only virtual member functions can be marked 'final'}} 73*f4a2713aSLionel Sambuc }; 74*f4a2713aSLionel Sambuc B<int> b; // no-note 75*f4a2713aSLionel Sambuc template<typename T> struct C : T { 76*f4a2713aSLionel Sambuc void g() override; 77*f4a2713aSLionel Sambuc void i() final; 78*f4a2713aSLionel Sambuc }; 79*f4a2713aSLionel Sambuc template<typename T> struct D : X { 80*f4a2713aSLionel Sambuc virtual void g() override; // expected-error {{does not override}} 81*f4a2713aSLionel Sambuc virtual void i() final; 82*f4a2713aSLionel Sambuc }; 83*f4a2713aSLionel Sambuc template<typename...T> struct E : X { 84*f4a2713aSLionel Sambuc void f(T...) override; 85*f4a2713aSLionel Sambuc void g(T...) override; // expected-error {{only virtual member functions can be marked 'override'}} 86*f4a2713aSLionel Sambuc void h(T...) final; 87*f4a2713aSLionel Sambuc void i(T...) final; // expected-error {{only virtual member functions can be marked 'final'}} 88*f4a2713aSLionel Sambuc }; 89*f4a2713aSLionel Sambuc // FIXME: Diagnose these in the template definition, not in the instantiation. 90*f4a2713aSLionel Sambuc E<> e; // expected-note {{in instantiation of}} 91*f4a2713aSLionel Sambuc 92*f4a2713aSLionel Sambuc template<typename T> struct Y : T { 93*f4a2713aSLionel Sambuc void f() override; 94*f4a2713aSLionel Sambuc void h() final; 95*f4a2713aSLionel Sambuc }; 96*f4a2713aSLionel Sambuc template<typename T> struct Z : T { 97*f4a2713aSLionel Sambuc void g() override; // expected-error {{only virtual member functions can be marked 'override'}} 98*f4a2713aSLionel Sambuc void i() final; // expected-error {{only virtual member functions can be marked 'final'}} 99*f4a2713aSLionel Sambuc }; 100*f4a2713aSLionel Sambuc Y<X> y; 101*f4a2713aSLionel Sambuc Z<X> z; // expected-note {{in instantiation of}} 102*f4a2713aSLionel Sambuc } 103*f4a2713aSLionel Sambuc 104*f4a2713aSLionel Sambuc namespace MemberOfUnknownSpecialization { 105*f4a2713aSLionel Sambuc template<typename T> struct A { 106*f4a2713aSLionel Sambuc struct B {}; 107*f4a2713aSLionel Sambuc struct C : B { 108*f4a2713aSLionel Sambuc void f() override; 109*f4a2713aSLionel Sambuc }; 110*f4a2713aSLionel Sambuc }; 111*f4a2713aSLionel Sambuc 112*f4a2713aSLionel Sambuc template<> struct A<int>::B { 113*f4a2713aSLionel Sambuc virtual void f(); 114*f4a2713aSLionel Sambuc }; 115*f4a2713aSLionel Sambuc // ok 116*f4a2713aSLionel Sambuc A<int>::C c1; 117*f4a2713aSLionel Sambuc 118*f4a2713aSLionel Sambuc template<> struct A<char>::B { 119*f4a2713aSLionel Sambuc void f(); 120*f4a2713aSLionel Sambuc }; 121*f4a2713aSLionel Sambuc // expected-error@-13 {{only virtual member functions can be marked 'override'}} 122*f4a2713aSLionel Sambuc // expected-note@+1 {{in instantiation of}} 123*f4a2713aSLionel Sambuc A<char>::C c2; 124*f4a2713aSLionel Sambuc 125*f4a2713aSLionel Sambuc template<> struct A<double>::B { 126*f4a2713aSLionel Sambuc virtual void f() final; 127*f4a2713aSLionel Sambuc }; 128*f4a2713aSLionel Sambuc // expected-error@-20 {{declaration of 'f' overrides a 'final' function}} 129*f4a2713aSLionel Sambuc // expected-note@-3 {{here}} 130*f4a2713aSLionel Sambuc // expected-note@+1 {{in instantiation of}} 131*f4a2713aSLionel Sambuc A<double>::C c3; 132*f4a2713aSLionel Sambuc } 133*f4a2713aSLionel Sambuc 134*f4a2713aSLionel Sambuc namespace DiagnosticsQOI { 135*f4a2713aSLionel Sambuc struct X { 136*f4a2713aSLionel Sambuc virtual ~X(); 137*f4a2713aSLionel Sambuc virtual void foo(int x); // expected-note {{hidden overloaded virtual function}} 138*f4a2713aSLionel Sambuc virtual void bar(int x); // expected-note 2 {{hidden overloaded virtual function}} 139*f4a2713aSLionel Sambuc virtual void bar(float x); // expected-note 2 {{hidden overloaded virtual function}} 140*f4a2713aSLionel Sambuc }; 141*f4a2713aSLionel Sambuc 142*f4a2713aSLionel Sambuc struct Y : X { 143*f4a2713aSLionel Sambuc void foo(int x, int y) override; // expected-error {{non-virtual member function marked 'override' hides virtual member function}} 144*f4a2713aSLionel Sambuc void bar(double) override; // expected-error {{non-virtual member function marked 'override' hides virtual member functions}} 145*f4a2713aSLionel Sambuc void bar(long double) final; // expected-error {{non-virtual member function marked 'final' hides virtual member functions}} 146*f4a2713aSLionel Sambuc }; 147*f4a2713aSLionel Sambuc 148*f4a2713aSLionel Sambuc template<typename T> 149*f4a2713aSLionel Sambuc struct Z : T { 150*f4a2713aSLionel Sambuc static void foo() override; // expected-error {{only virtual member functions can be marked 'override'}} 151*f4a2713aSLionel Sambuc }; 152*f4a2713aSLionel Sambuc } 153