p3-0x.cpp 4.1 KB

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