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