== Why is this an issue?

In a base class, ``++virtual++`` indicates that a function can be overridden. In a derived class, it indicates an override. But given the specifier's dual meaning, it would be clearer and more sound to use derived class-specific specifiers instead: ``++override++`` or ``++final++``.

[source,cpp]
----
class Counter {
protected:
  int c = 0;
public:
  virtual void count() {
    c++;
  }
};
----

[source,cpp,diff-id=1,diff-type=noncompliant]
----
class FastCounter: public Counter {
public:
  virtual void count() {  // Noncompliant: ambiguous
    c += 2;
  }
};
----

* ``++override++`` indicates that a function is intended to override a base-class function. The compiler will issue a warning if this is not the case.


[source,cpp,diff-id=1,diff-type=compliant]
----
class FastCounter: public Counter {
public:
  void count() override {
    c += 2;
  }
};
----

* ``++final++`` indicates a function ``++override++`` that cannot itself be overridden. The compiler will issue a warning if the signature does not match the signature of a base-class ``++virtual++`` function. `override` is redundant when `final` is specified.

[source,cpp,diff-id=1,diff-type=compliant]
----
class FastCounter: public Counter {
public:
  void count() final {
    c += 2;
  }
};
----

== Resources

* {cpp} Core Guidelines - https://github.com/isocpp/CppCoreGuidelines/blob/e49158a/CppCoreGuidelines.md#c128-virtual-functions-should-specify-exactly-one-of-virtual-override-or-final[C.128: Virtual functions should specify exactly one of `virtual`, `override`, or `final`]

=== Related rules

* S1016 - Virtual functions should be declared with the "virtual" keyword


ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

* Annotate this function with "override" or "final".
* Use "override" or "final" instead of "virtual".
* Drop the "[virtual|override]" specifier; it is redundant.
* Drop the "virtual" and "override" specifiers; they are redundant.


=== Highlighting

specifier to be dropped


'''
== Comments And Links
(visible only on this page)

=== relates to: S1016

=== is related to: S3576

=== on 11 Dec 2015, 17:53:48 Ann Campbell wrote:
\[~evgeny.mandrikov] given the fact that it's only a compiler warning to have a ``++virtual++`` function in a derived class with a mismatched signature, do we want a rule on that?


E.G.

----
class BaseClass
{
    virtual void doTheThing() const;
}

class DerivedClass : public BaseClass
{
    virtual void doTheThing();
}
----

=== on 3 Feb 2016, 10:16:40 Freddy Mallet wrote:
Hi [~ann.campbell.2], that's a pretty good idea to have a dedicated rule for that which would be activated by default. You can go ahead.

=== on 3 Feb 2016, 19:52:34 Ann Campbell wrote:
RSPEC-3528

endif::env-github,rspecator-view[]
