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
10 // Purposely use macros to test that the FixIt hints don't try to remove the
12 #define OVERRIDE override
15 // Base class can only use virtual.
22 // Derived classes correctly use only override or final specifier.
23 class CorrectOverride
: public Base
{
25 ~CorrectOverride() OVERRIDE
{}
29 class CorrectFinal
: public CorrectOverride
{
31 ~CorrectFinal() FINAL
{}
35 // No override on an overridden method should trigger a diagnostic.
36 class MissingOverride
: public Base
{
42 // Redundant specifiers should trigger a diagnostic.
43 class VirtualAndOverride
: public Base
{
45 virtual ~VirtualAndOverride() OVERRIDE
{}
46 virtual void F() OVERRIDE
{}
49 class VirtualAndFinal
: public Base
{
51 virtual ~VirtualAndFinal() FINAL
{}
52 virtual void F() FINAL
{}
55 class VirtualAndOverrideFinal
: public Base
{
57 virtual ~VirtualAndOverrideFinal() OVERRIDE FINAL
{}
58 virtual void F() OVERRIDE FINAL
{}
61 class OverrideAndFinal
: public Base
{
63 ~OverrideAndFinal() OVERRIDE FINAL
{}
64 void F() OVERRIDE FINAL
{}
67 // Also warn on pure functions.
68 class CorrectPureVirtual
: public Base
{
72 class Pure
: public Base
{
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.
103 virtual void SetUp();
108 class MyTest
: public testing::Test
{
111 virtual void SetUp() override
;
114 class MyNotTest
: public testing::NotTest
{
116 virtual ~MyNotTest();
117 virtual void SetUp() override
;