Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: tools/clang/plugins/tests/virtual_specifiers.cpp

Issue 1385193002: Bisect clang Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 246985 Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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 //
5 // Tests for chromium style checks for virtual/override/final specifiers on
6 // virtual methods.
7
8 // Note: This is not actual windows.h but the stub file in system/windows.h
9 #include <windows.h>
10
11 // Purposely use macros to test that the FixIt hints don't try to remove the
12 // macro body.
13 #define OVERRIDE override
14 #define FINAL final
15
16 // Base class can only use virtual.
17 class Base {
18 public:
19 virtual ~Base() {}
20 virtual void F() = 0;
21 };
22
23 // Derived classes correctly use only override or final specifier.
24 class CorrectOverride : public Base {
25 public:
26 ~CorrectOverride() OVERRIDE {}
27 void F() OVERRIDE {}
28 };
29
30 class CorrectFinal : public CorrectOverride {
31 public:
32 ~CorrectFinal() FINAL {}
33 void F() FINAL {}
34 };
35
36 // No override on an overridden method should trigger a diagnostic.
37 class MissingOverride : public Base {
38 public:
39 ~MissingOverride() {}
40 void F() {}
41 };
42
43 // Redundant specifiers should trigger a diagnostic.
44 class VirtualAndOverride : public Base {
45 public:
46 virtual ~VirtualAndOverride() OVERRIDE {}
47 virtual void F() OVERRIDE {}
48 };
49
50 class VirtualAndFinal : public Base {
51 public:
52 virtual ~VirtualAndFinal() FINAL {}
53 virtual void F() FINAL {}
54 };
55
56 class VirtualAndOverrideFinal : public Base {
57 public:
58 virtual ~VirtualAndOverrideFinal() OVERRIDE FINAL {}
59 virtual void F() OVERRIDE FINAL {}
60 };
61
62 class OverrideAndFinal : public Base {
63 public:
64 ~OverrideAndFinal() OVERRIDE FINAL {}
65 void F() OVERRIDE FINAL {}
66 };
67
68 // Also warn on pure functions.
69 class CorrectPureVirtual : public Base {
70 virtual void F() = 0;
71 };
72
73 class Pure : public Base {
74 void F() = 0;
75 };
76
77 class PureOverride : public Base {
78 void F() override = 0;
79 };
80
81 class PureVirtualOverride : public Base {
82 virtual void F() override = 0;
83 };
84
85 // Test that the redundant virtual warning is suppressed when the virtual
86 // keyword comes from a macro in a system header.
87 class COMIsAwesome : public Base {
88 STDMETHOD(F)() override = 0;
89 };
90
91 // Some tests that overrides in the testing namespace
92 // don't trigger warnings, except for testing::Test.
93 namespace testing {
94
95 class Test {
96 public:
97 virtual ~Test();
98 virtual void SetUp();
99 };
100
101 class NotTest {
102 public:
103 virtual ~NotTest();
104 virtual void SetUp();
105 };
106
107 } // namespace
108
109 class MyTest : public testing::Test {
110 public:
111 virtual ~MyTest();
112 virtual void SetUp() override;
113 };
114
115 class MyNotTest : public testing::NotTest {
116 public:
117 virtual ~MyNotTest();
118 virtual void SetUp() override;
119 };
120
121 class MacroBase {
122 public:
123 virtual void AddRef() = 0;
124 virtual void Virtual() {}
125 };
126
127 class Sub : public MacroBase {
128 // Shouldn't warn.
129 END_COM_MAP()
130 SYSTEM_REDUNDANT1;
131 SYSTEM_REDUNDANT2;
132 };
OLDNEW
« no previous file with comments | « tools/clang/plugins/tests/virtual_bodies.txt ('k') | tools/clang/plugins/tests/virtual_specifiers.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698