Skip to content

Commit b243477

Browse files
committed
address review comments
1 parent 5bdf858 commit b243477

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ C++23 Feature Support
209209
- Added a ``__reference_converts_from_temporary`` builtin, completing the necessary compiler support for
210210
`P2255R2: Type trait to determine if a reference binds to a temporary <https://wg21.link/P2255R2>`_.
211211

212-
- Implemented `P2797R0: Static and explicit object member functions with the same parameter-type-lists <https://wg21.link/P2797R0>`.
212+
- Implemented `P2797R0: Static and explicit object member functions with the same parameter-type-lists <https://wg21.link/P2797R0>`_.
213213
This completes the support for "deducing this".
214214

215215
C++2c Feature Support

clang/lib/Sema/SemaOverload.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7554,11 +7554,16 @@ Sema::AddMethodCandidate(CXXMethodDecl *Method, DeclAccessPair FoundDecl,
75547554
(Method->isExplicitObjectMemberFunction() &&
75557555
CandidateSet.getKind() ==
75567556
OverloadCandidateSet::CSK_AddressOfOverloadSet);
7557+
bool ImplicitObjectMethodTreatedAsStatic =
7558+
CandidateSet.getKind() ==
7559+
OverloadCandidateSet::CSK_AddressOfOverloadSet &&
7560+
Method->isImplicitObjectMemberFunction();
7561+
75577562
unsigned ExplicitOffset =
75587563
!IgnoreExplicitObject && Method->isExplicitObjectMemberFunction() ? 1 : 0;
7559-
unsigned NumParams = Method->getNumParams() - ExplicitOffset;
7560-
if (CandidateSet.getKind() == OverloadCandidateSet::CSK_AddressOfOverloadSet)
7561-
NumParams += int(Method->isImplicitObjectMemberFunction());
7564+
7565+
unsigned NumParams = Method->getNumParams() - ExplicitOffset +
7566+
int(ImplicitObjectMethodTreatedAsStatic);
75627567

75637568
// (C++ 13.3.2p2): A candidate function having fewer than m
75647569
// parameters is viable only if it has an ellipsis in its parameter
@@ -7576,11 +7581,9 @@ Sema::AddMethodCandidate(CXXMethodDecl *Method, DeclAccessPair FoundDecl,
75767581
// (8.3.6). For the purposes of overload resolution, the
75777582
// parameter list is truncated on the right, so that there are
75787583
// exactly m parameters.
7579-
unsigned MinRequiredArgs = Method->getMinRequiredArguments() - ExplicitOffset;
7580-
if (CandidateSet.getKind() ==
7581-
OverloadCandidateSet::CSK_AddressOfOverloadSet &&
7582-
Method->isImplicitObjectMemberFunction())
7583-
MinRequiredArgs++;
7584+
unsigned MinRequiredArgs = Method->getMinRequiredArguments() -
7585+
ExplicitOffset +
7586+
int(ImplicitObjectMethodTreatedAsStatic);
75847587

75857588
if (Args.size() < MinRequiredArgs && !PartialOverloading) {
75867589
// Not enough arguments.
@@ -7652,9 +7655,7 @@ Sema::AddMethodCandidate(CXXMethodDecl *Method, DeclAccessPair FoundDecl,
76527655
// (13.3.3.1) that converts that argument to the corresponding
76537656
// parameter of F.
76547657
QualType ParamType;
7655-
if (CandidateSet.getKind() ==
7656-
OverloadCandidateSet::CSK_AddressOfOverloadSet &&
7657-
Method->isImplicitObjectMemberFunction()) {
7658+
if (ImplicitObjectMethodTreatedAsStatic) {
76587659
ParamType = ArgIdx == 0
76597660
? Method->getFunctionObjectParameterReferenceType()
76607661
: Proto->getParamType(ArgIdx - 1);
@@ -16402,8 +16403,8 @@ ExprResult Sema::FixOverloadedFunctionReference(Expr *E, DeclAccessPair Found,
1640216403
"Can only take the address of an overloaded function");
1640316404
if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Fn)) {
1640416405
if (!Method->isImplicitObjectMemberFunction()) {
16405-
// Do nothing: static member functions aren't any different
16406-
// from non-member functions.
16406+
// Do nothing: the address of static and
16407+
// explicit object member functions is a (non-member) function pointer.
1640716408
} else {
1640816409
// Fix the subexpression, which really has to be an
1640916410
// UnresolvedLookupExpr holding an overloaded member function

clang/test/CXX/drs/cwg26xx.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ void test() {
242242
#endif
243243

244244

245-
#if __cplusplus >= 202302L
246245
namespace cwg2692 { // cwg2692: 19
246+
#if __cplusplus >= 202302L
247247

248248
struct A {
249249
static void f(A); // #cwg2692-1
@@ -253,16 +253,17 @@ namespace cwg2692 { // cwg2692: 19
253253
};
254254

255255
void A::g() {
256-
(&A::f)(A()); // expected-error {{call to 'f' is ambiguous}}
257-
// expected-note@#cwg2692-1 {{candidate}}
258-
// expected-note@#cwg2692-2 {{candidate}}
256+
(&A::f)(A());
257+
// expected-error@-1 {{call to 'f' is ambiguous}}
258+
// expected-note@#cwg2692-1 {{candidate}}
259+
// expected-note@#cwg2692-2 {{candidate}}
259260

260261

261262

262-
(&A::f)(); // expected-error {{no matching function for call to 'f'}}
263-
// expected-note@#cwg2692-1 {{candidate function not viable: requires 1 argument, but 0 were provided}}
264-
// expected-note@#cwg2692-2 {{candidate function not viable: requires 1 argument, but 0 were provided}}
263+
(&A::f)();
264+
// expected-error@-1 {{no matching function for call to 'f'}}
265+
// expected-note@#cwg2692-1 {{candidate function not viable: requires 1 argument, but 0 were provided}}
266+
// expected-note@#cwg2692-2 {{candidate function not viable: requires 1 argument, but 0 were provided}}
265267
}
266-
267-
}
268268
#endif
269+
}

clang/test/CXX/drs/cwg2771.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ struct A{
1515
// CXX23-NEXT: UnaryOperator
1616
// CXX23-NEXT: MemberExpr
1717
// CXX23-NEXT: CXXThisExpr{{.+}}'cwg2771::A *'
18-
}
18+
19+
} // namespace cwg2771

0 commit comments

Comments
 (0)