Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / tools / clang / plugins / tests / virtual_specifiers.cpp
blob210324809f1ee7d7a41ad3f3108a61f52d6ffd9f
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 #include <windows.h>
10 // Purposely use macros to test that the FixIt hints don't try to remove the
11 // macro body.
12 #define OVERRIDE override
13 #define FINAL final
15 // Base class can only use virtual.
16 class Base {
17 public:
18 virtual ~Base() {}
19 virtual void F() = 0;
22 // Derived classes correctly use only override or final specifier.
23 class CorrectOverride : public Base {
24 public:
25 ~CorrectOverride() OVERRIDE {}
26 void F() OVERRIDE {}
29 class CorrectFinal : public CorrectOverride {
30 public:
31 ~CorrectFinal() FINAL {}
32 void F() FINAL {}
35 // No override on an overridden method should trigger a diagnostic.
36 class MissingOverride : public Base {
37 public:
38 ~MissingOverride() {}
39 void F() {}
42 // Redundant specifiers should trigger a diagnostic.
43 class VirtualAndOverride : public Base {
44 public:
45 virtual ~VirtualAndOverride() OVERRIDE {}
46 virtual void F() OVERRIDE {}
49 class VirtualAndFinal : public Base {
50 public:
51 virtual ~VirtualAndFinal() FINAL {}
52 virtual void F() FINAL {}
55 class VirtualAndOverrideFinal : public Base {
56 public:
57 virtual ~VirtualAndOverrideFinal() OVERRIDE FINAL {}
58 virtual void F() OVERRIDE FINAL {}
61 class OverrideAndFinal : public Base {
62 public:
63 ~OverrideAndFinal() OVERRIDE FINAL {}
64 void F() OVERRIDE FINAL {}
67 // Also warn on pure functions.
68 class CorrectPureVirtual : public Base {
69 virtual void F() = 0;
72 class Pure : public Base {
73 void F() = 0;
76 class PureOverride : public Base {
77 void F() override = 0;
80 class PureVirtualOverride : public Base {
81 virtual void F() override = 0;
84 // Test that the redundant virtual warning is suppressed when the virtual
85 // keyword comes from a macro in a system header.
86 class COMIsAwesome : public Base {
87 STDMETHOD(F)() override = 0;
90 // Some tests that overrides in the testing namespace
91 // don't trigger warnings, except for testing::Test.
92 namespace testing {
94 class Test {
95 public:
96 virtual ~Test();
97 virtual void SetUp();
100 class NotTest {
101 public:
102 virtual ~NotTest();
103 virtual void SetUp();
106 } // namespace
108 class MyTest : public testing::Test {
109 public:
110 virtual ~MyTest();
111 virtual void SetUp() override;
114 class MyNotTest : public testing::NotTest {
115 public:
116 virtual ~MyNotTest();
117 virtual void SetUp() override;