Skip to content

[class.virtual] Explicit object member functions cannot be virtual CWG2553 #5145

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions source/classes.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2991,6 +2991,10 @@
\end{codeblock}
\end{note}

\pnum
An allocation or deallocation function for a class
shall not have an explicit object parameter\iref{dcl.fct}.

\pnum
Access to the deallocation function is checked statically,
even if a different one is actually executed.
Expand Down Expand Up @@ -3870,6 +3874,21 @@
\end{codeblock}
\end{example}

\pnum
A virtual function shall not be an explicit object member
function\iref{dcl.fct}.
\begin{example}
\begin{codeblock}
struct B {
virtual void g(); // \#1
};
struct D : B {
virtual void f(this D&); // error: explicit object member function cannot be virtual
void g(this D&); // overrides \#1; error: explicit object member function cannot be virtual
};
\end{codeblock}
\end{example}

\pnum
The \grammarterm{ref-qualifier}, or lack thereof, of an overriding function
shall be the same as that of the overridden function.
Expand Down
2 changes: 1 addition & 1 deletion source/declarations.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3579,7 +3579,7 @@
A \grammarterm{member-declarator} with an explicit-object-parameter-declaration
shall not include
a \grammarterm{ref-qualifier} or a \grammarterm{cv-qualifier-seq} and
shall not be declared \keyword{static} or \keyword{virtual}.
shall not be declared \keyword{static}.
Copy link
Member

@zygoloid zygoloid Dec 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have the same problem with the implicit static for allocation functions?

struct A {
  // I'm not sure which parameter needs to be size_t, but
  // one of them does...
  /*implicitly static*/
  void *operator new(this size_t a, size_t b);
};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See separate commit.

\begin{example}
\begin{codeblock}
struct C {
Expand Down