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.
5 // Tests for chromium style checks for virtual/override/final specifiers on
8 // Note: This is not actual windows.h but the stub file in system/windows.h
11 // Purposely use macros to test that the FixIt hints don't try to remove the
13 #define OVERRIDE override
16 // Base class can only use virtual.
23 // Derived classes correctly use only override or final specifier.
24 class CorrectOverride
: public Base
{
26 ~CorrectOverride() OVERRIDE
{}
30 class CorrectFinal
: public CorrectOverride
{
32 ~CorrectFinal() FINAL
{}
36 // No override on an overridden method should trigger a diagnostic.
37 class MissingOverride
: public Base
{
43 // Redundant specifiers should trigger a diagnostic.
44 class VirtualAndOverride
: public Base
{
46 virtual ~VirtualAndOverride() OVERRIDE
{}
47 virtual void F() OVERRIDE
{}
50 class VirtualAndFinal
: public Base
{
52 virtual ~VirtualAndFinal() FINAL
{}
53 virtual void F() FINAL
{}
56 class VirtualAndOverrideFinal
: public Base
{
58 virtual ~VirtualAndOverrideFinal() OVERRIDE FINAL
{}
59 virtual void F() OVERRIDE FINAL
{}
62 class OverrideAndFinal
: public Base
{
64 ~OverrideAndFinal() OVERRIDE FINAL
{}
65 void F() OVERRIDE FINAL
{}
68 // Also warn on pure functions.
69 class CorrectPureVirtual
: public Base
{
73 class Pure
: public Base
{
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.
104 virtual void SetUp();
109 class MyTest
: public testing::Test
{
112 virtual void SetUp() override
;
115 class MyNotTest
: public testing::NotTest
{
117 virtual ~MyNotTest();
118 virtual void SetUp() override
;
123 virtual void AddRef() = 0;
124 virtual void Virtual() {}
127 class Sub
: public MacroBase
{