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 // Purposely use macros to test that the FixIt hints don't try to remove the
10 #define OVERRIDE override
13 // Base class can only use virtual.
20 // Derived classes correctly use only override or final specifier.
21 class CorrectOverride
: public Base
{
23 ~CorrectOverride() OVERRIDE
{}
27 class CorrectFinal
: public CorrectOverride
{
29 ~CorrectFinal() FINAL
{}
33 // No override on an overridden method should trigger a diagnostic.
34 class MissingOverride
: public Base
{
40 // Redundant specifiers should trigger a diagnostic.
41 class VirtualAndOverride
: public Base
{
43 virtual ~VirtualAndOverride() OVERRIDE
{}
44 virtual void F() OVERRIDE
{}
47 class VirtualAndFinal
: public Base
{
49 virtual ~VirtualAndFinal() FINAL
{}
50 virtual void F() FINAL
{}
53 class VirtualAndOverrideFinal
: public Base
{
55 virtual ~VirtualAndOverrideFinal() OVERRIDE FINAL
{}
56 virtual void F() OVERRIDE FINAL
{}
59 class OverrideAndFinal
: public Base
{
61 ~OverrideAndFinal() OVERRIDE FINAL
{}
62 void F() OVERRIDE FINAL
{}
65 // Also warn on pure functions.
66 class CorrectPureVirtual
: public Base
{
70 class Pure
: public Base
{
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.
100 class MyTest
: public testing::Test
{
103 virtual void SetUp() override
;
106 class MyNotTest
: public testing::NotTest
{
108 virtual ~MyNotTest();
109 virtual void SetUp() override
;