Skip to content

[CWG 10] P2797R0 Proposed resolution for CWG2692 Static and explicit object me… #6125

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

Merged
merged 1 commit into from
Mar 5, 2023
Merged
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
7 changes: 4 additions & 3 deletions source/classes.tex
Original file line number Diff line number Diff line change
Expand Up @@ -944,9 +944,10 @@
a member thereof, as described below.

\pnum
When an \grammarterm{id-expression}\iref{expr.prim.id} that is not part of a
class member access syntax\iref{expr.ref} and not used to form a
pointer to member\iref{expr.unary.op} is used
When an \grammarterm{id-expression}\iref{expr.prim.id} that is
neither part of a class member access syntax\iref{expr.ref}
nor the unparenthesized operand of
the unary \tcode{\&} operator\iref{expr.unary.op} is used
where the current class is \tcode{X}\iref{expr.prim.this},
if name
lookup\iref{basic.lookup} resolves the name in the
Expand Down
17 changes: 1 addition & 16 deletions source/expressions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@

\pnum
An \grammarterm{id-expression} that denotes a non-static data member or
non-static member function of a class can only be used:
implicit object member function of a class can only be used:
\begin{itemize}
\item as part of a class member access\iref{expr.ref} in which the
object expression
Expand Down Expand Up @@ -3171,21 +3171,6 @@
conversion\iref{conv.func} is suppressed on the postfix expression),
or have function pointer type.

\pnum
For a call to a non-static member function,
the postfix expression shall be an
implicit\iref{class.mfct.non.static,class.static} or explicit
class member access\iref{expr.ref} whose \grammarterm{id-expression} is a
function member name, or a pointer-to-member
expression\iref{expr.mptr.oper} selecting a function member; the call is as a member of
the class object referred to by the
object expression. In the case of an implicit class
member access, the implied object is the one pointed to by \keyword{this}.
\begin{note}
A member function call of the form \tcode{f()} is interpreted as
\tcode{(*\keyword{this}).f()} (see~\ref{class.mfct.non.static}).
\end{note}

\pnum
If the selected
function is non-virtual, or if the \grammarterm{id-expression} in the class
Expand Down
46 changes: 33 additions & 13 deletions source/overloading.tex
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,17 @@
\indextext{function!overload resolution and}%
The set of candidate functions can contain both member and non-member
functions to be resolved against the same argument list.
So that argument and parameter lists are comparable within this
heterogeneous set, a member function that does not have an explicit object parameter is considered to have an
extra first parameter, called the
\defn{implicit object parameter},
which represents the object for which the member function has been
called.
For the purposes of overload resolution, both static and
non-static member functions have an object parameter,
but constructors do not.
If a member function is
\begin{itemize}
\item
an implicit object member function that is not a constructor, or
\item
a static member function and
the argument list includes an implied object argument,
\end{itemize}
it is considered to have an extra first parameter,
called the \defnadj{implicit}{object parameter},
which represents the object for which the member function has been called.

\pnum
Similarly, when appropriate, the context can construct an
Expand Down Expand Up @@ -367,7 +369,11 @@
\pnum
If the \grammarterm{postfix-expression} is the address of an overload set,
overload resolution is applied using that set as described above.
If the function selected by overload resolution is a non-static member function,
\begin{note}
No implied object argument is added in this case.
\end{note}
If the function selected by overload resolution is
an implicit object member function,
the program is ill-formed.
\begin{note}
The resolution of the address of an
Expand Down Expand Up @@ -443,15 +449,16 @@
The function declarations found by name lookup\iref{basic.lookup} constitute the
set of candidate functions.
Because of the rules for name lookup, the set of candidate functions
consists (1) entirely of non-member functions or (2) entirely of
consists either entirely of non-member functions or entirely of
member functions of some class
\tcode{T}.
In case (1),
In the former case or
if the \grammarterm{primary-expression} is the address of an overload set,
the argument list is
the same as the
\grammarterm{expression-list}
in the call.
In case (2), the argument list is the
Otherwise, the argument list is the
\grammarterm{expression-list}
in the call augmented by the addition of an implied object
argument as in a qualified function call.
Expand Down Expand Up @@ -485,6 +492,19 @@
a(); // OK, \tcode{(*this).a()}
}

void c(this const C&); // \#1
void c()&; // \#2
static void c(int = 0); // \#3

void d() {
c(); // error: ambiguous between \#2 and \#3
(C::c)(); // error: as above
(&(C::c))(); // error: cannot resolve address of overloaded \tcode{this->C::c}\iref{over.over}
(&C::c)(C{}); // selects \#1
(&C::c)(*this); // error: selects \#2, and is ill-formed\iref{over.match.call.general}
(&C::c)(); // selects \#3
}

void f(this const C&);
void g() const {
f(); // OK, \tcode{(*this).f()}
Expand Down