Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / tools / clang / plugins / tests / virtual_specifiers.cpp
blob28321e8bdf5c29aed7fd2343b398eb8cad360b6c
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.
8 // Purposely use macros to test that the FixIt hints don't try to remove the
9 // macro body.
10 #define OVERRIDE override
11 #define FINAL final
13 // Base class can only use virtual.
14 class Base {
15 public:
16 virtual ~Base() {}
17 virtual void F() = 0;
20 // Derived classes correctly use only override or final specifier.
21 class CorrectOverride : public Base {
22 public:
23 ~CorrectOverride() OVERRIDE {}
24 void F() OVERRIDE {}
27 class CorrectFinal : public CorrectOverride {
28 public:
29 ~CorrectFinal() FINAL {}
30 void F() FINAL {}
33 // No override on an overridden method should trigger a diagnostic.
34 class MissingOverride : public Base {
35 public:
36 ~MissingOverride() {}
37 void F() {}
40 // Redundant specifiers should trigger a diagnostic.
41 class VirtualAndOverride : public Base {
42 public:
43 virtual ~VirtualAndOverride() OVERRIDE {}
44 virtual void F() OVERRIDE {}
47 class VirtualAndFinal : public Base {
48 public:
49 virtual ~VirtualAndFinal() FINAL {}
50 virtual void F() FINAL {}
53 class VirtualAndOverrideFinal : public Base {
54 public:
55 virtual ~VirtualAndOverrideFinal() OVERRIDE FINAL {}
56 virtual void F() OVERRIDE FINAL {}
59 class OverrideAndFinal : public Base {
60 public:
61 ~OverrideAndFinal() OVERRIDE FINAL {}
62 void F() OVERRIDE FINAL {}
65 // Also warn on pure functions.
66 class CorrectPureVirtual : public Base {
67 virtual void F() = 0;
70 class Pure : public Base {
71 void F() = 0;
74 class PureOverride : public Base {
75 void F() override = 0;
78 class PureVirtualOverride : public Base {
79 virtual void F() override = 0;
82 // Finally, some simple sanity tests that overrides in the testing namespace
83 // don't trigger warnings, except for testing::Test.
84 namespace testing {
86 class Test {
87 public:
88 virtual ~Test();
89 virtual void SetUp();
92 class NotTest {
93 public:
94 virtual ~NotTest();
95 virtual void SetUp();
98 } // namespace
100 class MyTest : public testing::Test {
101 public:
102 virtual ~MyTest();
103 virtual void SetUp() override;
106 class MyNotTest : public testing::NotTest {
107 public:
108 virtual ~MyNotTest();
109 virtual void SetUp() override;