Skip to content

Commit 5f68072

Browse files
authored
[Clang][Sema] Fix issue on requires expression with templated base class member function (#85198)
Fix #84020 Skip checking implicit object parameter in the context of `RequiresExprBodyDecl`. Co-authored-by: huqizhi <[email protected]>
1 parent 4b22a92 commit 5f68072

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ Bug Fixes to C++ Support
538538
object parameter.
539539
Fixes (#GH70604), (#GH79754), (#GH84163), (#GH84425), (#GH86054), (#GH86398), and (#GH86399).
540540
- Fix a crash when deducing ``auto`` from an invalid dereference (#GH88329).
541+
- Fix a crash in requires expression with templated base class member function. Fixes (#GH84020).
541542

542543
Bug Fixes to AST Handling
543544
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaExpr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7739,7 +7739,8 @@ ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl,
77397739
}
77407740

77417741
if (CXXMethodDecl *Method = dyn_cast_or_null<CXXMethodDecl>(FDecl))
7742-
if (Method->isImplicitObjectMemberFunction())
7742+
if (!isa<RequiresExprBodyDecl>(CurContext) &&
7743+
Method->isImplicitObjectMemberFunction())
77437744
return ExprError(Diag(LParenLoc, diag::err_member_call_without_object)
77447745
<< Fn->getSourceRange() << 0);
77457746

clang/test/SemaCXX/PR84020.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %clang_cc1 -std=c++20 -verify %s
2+
// RUN: %clang_cc1 -std=c++23 -verify %s
3+
// expected-no-diagnostics
4+
5+
struct B {
6+
template <typename S>
7+
void foo();
8+
9+
void bar();
10+
};
11+
12+
template <typename T, typename S>
13+
struct A : T {
14+
auto foo() {
15+
static_assert(requires { T::template foo<S>(); });
16+
static_assert(requires { T::bar(); });
17+
}
18+
};
19+
20+
int main() {
21+
A<B, double> a;
22+
a.foo();
23+
}

0 commit comments

Comments
 (0)