Skip to content

Cleanup of [class.virtual] #3987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions source/classes.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3748,7 +3748,7 @@

\pnum
A non-static member function is a \defnadj{virtual}{function}
if it is first declared with the keyword \tcode{virtual} or
if it is declared with the keyword \tcode{virtual} or
if it overrides a virtual member function declared in a base class
(see below).\footnote{The use of the \tcode{virtual} specifier in the
declaration of an overriding function is valid but redundant (has empty
Expand All @@ -3765,24 +3765,21 @@
any additions for that polymorphic behavior.}

\pnum
If a virtual member function \tcode{vf} is declared in a class
\tcode{Base} and in a class \tcode{Derived}, derived directly or
indirectly from \tcode{Base}, a member function \tcode{vf} with the same
name, parameter-type-list\iref{dcl.fct}, cv-qualification, and ref-qualifier
(or absence of same) as \tcode{Base::vf} is declared,
then \tcode{Derived::vf} \term{overrides}\footnote{A function
A non-template non-static member function declared in a class \tcode{D}
\defn{overrides} a virtual member function declared
in a base class of \tcode{D} if both have the same name,
parameter-type-list\iref{dcl.fct}, \grammarterm{cv-qualifier-seq},
and \grammarterm{ref-qualifier} (or absence thereof).
\footnote{A function
with the same name but a different parameter list\iref{over}
as a virtual function is not necessarily virtual and
does not override. Access control\iref{class.access} is not considered in
determining overriding.}
\tcode{Base::vf}. For convenience we say that any virtual function
overrides itself.
\indextext{overrider!final}%
A virtual member function \tcode{C::vf} of a class object \tcode{S} is a \defn{final
overrider} unless the most derived class\iref{intro.object} of which \tcode{S} is a
base class subobject (if any) declares or inherits another member function that overrides
\tcode{vf}. In a derived class, if a virtual member function of a base class subobject
has more than one final overrider the program is ill-formed.
The \denfx{final overrider}{overrider!final} of a virtual function \tcode{F} in a class \tcode{C}
is \tcode{F} if no member of \tcode{C} overrides \tcode{F},
and otherwise is the member \tcode{G} of \tcode{C} that overrides \tcode{F}
and itself is not overridden by any other member of \tcode{C};
there shall be exactly one such \tcode{G}.
\begin{example}
\begin{codeblock}
struct A {
Expand Down Expand Up @@ -3838,9 +3835,8 @@
\end{note}

\pnum
If a virtual function \tcode{f} in some class \tcode{B} is marked with the
\grammarterm{virt-specifier} \tcode{final} and in a class \tcode{D} derived from \tcode{B}
a function \tcode{D::f} overrides \tcode{B::f}, the program is ill-formed.
A virtual function shall not override a function declared
with the \grammarterm{virt-specifier} \tcode{final}.
\begin{example}
\begin{codeblock}
struct B {
Expand All @@ -3854,8 +3850,8 @@
\end{example}

\pnum
If a virtual function is marked with the \grammarterm{virt-specifier} \tcode{override} and
does not override a member function of a base class, the program is ill-formed.
A function declared with the \grammarterm{virt-specifier} \tcode{override}
shall override a virtual function.
\begin{example}
\begin{codeblock}
struct B {
Expand Down
2 changes: 2 additions & 0 deletions source/templates.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2597,6 +2597,7 @@
\end{example}

\pnum
\begin{note}
A specialization of
a member function template does not override a virtual function from a
base class.
Expand All @@ -2612,6 +2613,7 @@
};
\end{codeblock}
\end{example}
\end{note}

\pnum
A specialization of a
Expand Down