Skip to content

Commit a6550ab

Browse files
authored
Merge 2023-02 CWG Motion 10
P2797R0 Proposed resolution for CWG2692 Static and explicit object member functions with the same parameter-type-lists
2 parents ea304e6 + 3ff7149 commit a6550ab

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

source/classes.tex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -944,9 +944,10 @@
944944
a member thereof, as described below.
945945

946946
\pnum
947-
When an \grammarterm{id-expression}\iref{expr.prim.id} that is not part of a
948-
class member access syntax\iref{expr.ref} and not used to form a
949-
pointer to member\iref{expr.unary.op} is used
947+
When an \grammarterm{id-expression}\iref{expr.prim.id} that is
948+
neither part of a class member access syntax\iref{expr.ref}
949+
nor the unparenthesized operand of
950+
the unary \tcode{\&} operator\iref{expr.unary.op} is used
950951
where the current class is \tcode{X}\iref{expr.prim.this},
951952
if name
952953
lookup\iref{basic.lookup} resolves the name in the

source/expressions.tex

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@
13411341

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

3174-
\pnum
3175-
For a call to a non-static member function,
3176-
the postfix expression shall be an
3177-
implicit\iref{class.mfct.non.static,class.static} or explicit
3178-
class member access\iref{expr.ref} whose \grammarterm{id-expression} is a
3179-
function member name, or a pointer-to-member
3180-
expression\iref{expr.mptr.oper} selecting a function member; the call is as a member of
3181-
the class object referred to by the
3182-
object expression. In the case of an implicit class
3183-
member access, the implied object is the one pointed to by \keyword{this}.
3184-
\begin{note}
3185-
A member function call of the form \tcode{f()} is interpreted as
3186-
\tcode{(*\keyword{this}).f()} (see~\ref{class.mfct.non.static}).
3187-
\end{note}
3188-
31893174
\pnum
31903175
If the selected
31913176
function is non-virtual, or if the \grammarterm{id-expression} in the class

source/overloading.tex

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,17 @@
154154
\indextext{function!overload resolution and}%
155155
The set of candidate functions can contain both member and non-member
156156
functions to be resolved against the same argument list.
157-
So that argument and parameter lists are comparable within this
158-
heterogeneous set, a member function that does not have an explicit object parameter is considered to have an
159-
extra first parameter, called the
160-
\defn{implicit object parameter},
161-
which represents the object for which the member function has been
162-
called.
163-
For the purposes of overload resolution, both static and
164-
non-static member functions have an object parameter,
165-
but constructors do not.
157+
If a member function is
158+
\begin{itemize}
159+
\item
160+
an implicit object member function that is not a constructor, or
161+
\item
162+
a static member function and
163+
the argument list includes an implied object argument,
164+
\end{itemize}
165+
it is considered to have an extra first parameter,
166+
called the \defnadj{implicit}{object parameter},
167+
which represents the object for which the member function has been called.
166168

167169
\pnum
168170
Similarly, when appropriate, the context can construct an
@@ -367,7 +369,11 @@
367369
\pnum
368370
If the \grammarterm{postfix-expression} is the address of an overload set,
369371
overload resolution is applied using that set as described above.
370-
If the function selected by overload resolution is a non-static member function,
372+
\begin{note}
373+
No implied object argument is added in this case.
374+
\end{note}
375+
If the function selected by overload resolution is
376+
an implicit object member function,
371377
the program is ill-formed.
372378
\begin{note}
373379
The resolution of the address of an
@@ -443,15 +449,16 @@
443449
The function declarations found by name lookup\iref{basic.lookup} constitute the
444450
set of candidate functions.
445451
Because of the rules for name lookup, the set of candidate functions
446-
consists (1) entirely of non-member functions or (2) entirely of
452+
consists either entirely of non-member functions or entirely of
447453
member functions of some class
448454
\tcode{T}.
449-
In case (1),
455+
In the former case or
456+
if the \grammarterm{primary-expression} is the address of an overload set,
450457
the argument list is
451458
the same as the
452459
\grammarterm{expression-list}
453460
in the call.
454-
In case (2), the argument list is the
461+
Otherwise, the argument list is the
455462
\grammarterm{expression-list}
456463
in the call augmented by the addition of an implied object
457464
argument as in a qualified function call.
@@ -485,6 +492,19 @@
485492
a(); // OK, \tcode{(*this).a()}
486493
}
487494

495+
void c(this const C&); // \#1
496+
void c()&; // \#2
497+
static void c(int = 0); // \#3
498+
499+
void d() {
500+
c(); // error: ambiguous between \#2 and \#3
501+
(C::c)(); // error: as above
502+
(&(C::c))(); // error: cannot resolve address of overloaded \tcode{this->C::c}\iref{over.over}
503+
(&C::c)(C{}); // selects \#1
504+
(&C::c)(*this); // error: selects \#2, and is ill-formed\iref{over.match.call.general}
505+
(&C::c)(); // selects \#3
506+
}
507+
488508
void f(this const C&);
489509
void g() const {
490510
f(); // OK, \tcode{(*this).f()}

0 commit comments

Comments
 (0)