[MD settings] moving attached() code
[chromium-blink-merge.git] / tools / clang / plugins / tests / virtual_specifiers.cpp
blobf566ac4f2a6cd205c493f8446803f7f397d29ab2
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 // Note: This is not actual windows.h but the stub file in system/windows.h
9 #include <windows.h>
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
16 // Base class can only use virtual.
17 class Base {
18 public:
19 virtual ~Base() {}
20 virtual void F() = 0;
23 // Derived classes correctly use only override or final specifier.
24 class CorrectOverride : public Base {
25 public:
26 ~CorrectOverride() OVERRIDE {}
27 void F() OVERRIDE {}
30 class CorrectFinal : public CorrectOverride {
31 public:
32 ~CorrectFinal() FINAL {}
33 void F() FINAL {}
36 // No override on an overridden method should trigger a diagnostic.
37 class MissingOverride : public Base {
38 public:
39 ~MissingOverride() {}
40 void F() {}
43 // Redundant specifiers should trigger a diagnostic.
44 class VirtualAndOverride : public Base {
45 public:
46 virtual ~VirtualAndOverride() OVERRIDE {}
47 virtual void F() OVERRIDE {}
50 class VirtualAndFinal : public Base {
51 public:
52 virtual ~VirtualAndFinal() FINAL {}
53 virtual void F() FINAL {}
56 class VirtualAndOverrideFinal : public Base {
57 public:
58 virtual ~VirtualAndOverrideFinal() OVERRIDE FINAL {}
59 virtual void F() OVERRIDE FINAL {}
62 class OverrideAndFinal : public Base {
63 public:
64 ~OverrideAndFinal() OVERRIDE FINAL {}
65 void F() OVERRIDE FINAL {}
68 // Also warn on pure functions.
69 class CorrectPureVirtual : public Base {
70 virtual void F() = 0;
73 class Pure : public Base {
74 void F() = 0;
77 class PureOverride : public Base {
78 void F() override = 0;
81 class PureVirtualOverride : public Base {
82 virtual void F() override = 0;
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;
91 // Some tests that overrides in the testing namespace
92 // don't trigger warnings, except for testing::Test.
93 namespace testing {
95 class Test {
96 public:
97 virtual ~Test();
98 virtual void SetUp();
101 class NotTest {
102 public:
103 virtual ~NotTest();
104 virtual void SetUp();
107 } // namespace
109 class MyTest : public testing::Test {
110 public:
111 virtual ~MyTest();
112 virtual void SetUp() override;
115 class MyNotTest : public testing::NotTest {
116 public:
117 virtual ~MyNotTest();
118 virtual void SetUp() override;
121 class MacroBase {
122 public:
123 virtual void AddRef() = 0;
124 virtual void Virtual() {}
127 class Sub : public MacroBase {
128 // Shouldn't warn.
129 END_COM_MAP()
130 SYSTEM_REDUNDANT1;
131 SYSTEM_REDUNDANT2;