overridden_methods.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef OVERRIDDEN_METHODS_H_
  5. #define OVERRIDDEN_METHODS_H_
  6. // Should warn about overriding of methods.
  7. class BaseClass {
  8. public:
  9. virtual ~BaseClass() {}
  10. virtual void SomeMethod() = 0;
  11. virtual void SomeOtherMethod() = 0;
  12. virtual void SomeInlineMethod() = 0;
  13. virtual void SomeConstMethod() const = 0;
  14. virtual void SomeMethodWithExceptionSpec() throw() = 0;
  15. virtual void SomeConstMethodWithExceptionSpec() const throw(int) = 0;
  16. virtual void SomeNonPureBaseMethod() {}
  17. virtual void SomeMethodWithComment() = 0;
  18. virtual void SomeMethodWithCommentAndBody() = 0;
  19. };
  20. class InterimClass : public BaseClass {
  21. // Should warn about pure virtual methods.
  22. virtual void SomeMethod() = 0;
  23. };
  24. namespace blink {
  25. class WebKitObserver {
  26. public:
  27. virtual void WebKitModifiedSomething() {}
  28. };
  29. } // namespace blink
  30. namespace webkit_glue {
  31. class WebKitObserverImpl : blink::WebKitObserver {
  32. public:
  33. virtual void WebKitModifiedSomething() {}
  34. };
  35. } // namespace webkit_glue
  36. class DerivedClass : public InterimClass,
  37. public webkit_glue::WebKitObserverImpl {
  38. public:
  39. // Should warn about destructors.
  40. virtual ~DerivedClass() {}
  41. // Should warn.
  42. virtual void SomeMethod();
  43. // Should not warn if marked as override.
  44. void SomeOtherMethod() override;
  45. // Should warn for inline implementations.
  46. virtual void SomeInlineMethod() {}
  47. // Should warn if overriding a method whose origin is blink.
  48. virtual void WebKitModifiedSomething();
  49. // Should warn with the insertion point after the const.
  50. virtual void SomeConstMethod() const {}
  51. // Should warn with the insertion point after the throw spec.
  52. virtual void SomeMethodWithExceptionSpec() throw() {}
  53. // Should warn with the insertion point after both the const and the throw
  54. // specifiers.
  55. virtual void SomeConstMethodWithExceptionSpec() const throw(int) {}
  56. // Should warn even if overridden method isn't pure.
  57. virtual void SomeNonPureBaseMethod() {}
  58. // Should warn and place correctly even when there is a comment.
  59. virtual void SomeMethodWithComment(); // This is a comment.
  60. // Should warn and place correctly even if there is a comment and body.
  61. virtual void SomeMethodWithCommentAndBody() {} // This is a comment.
  62. };
  63. class BaseClassWithDefaultedVirtualDtor {
  64. public:
  65. virtual ~BaseClassWithDefaultedVirtualDtor() = default;
  66. };
  67. class DerivedClassWithDefaultedDtor : public BaseClassWithDefaultedVirtualDtor {
  68. public:
  69. DerivedClassWithDefaultedDtor();
  70. ~DerivedClassWithDefaultedDtor() = default;
  71. };
  72. #endif // OVERRIDDEN_METHODS_H_