[clang] [Clang] Fix a crash when incorrectly calling an explicit object member function template (PR #75913)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 19 09:22:11 PST 2023
https://github.com/cor3ntin updated https://github.com/llvm/llvm-project/pull/75913
>From ba38db9f60f8a22e2a08f866e3540527131e16fb Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Tue, 19 Dec 2023 09:53:38 +0100
Subject: [PATCH 1/3] [Clang] Fix a crash when incorrectly calling an explicit
object member function template
Fixes #75732
---
clang/lib/Sema/SemaExprMember.cpp | 2 ++
clang/test/SemaCXX/cxx2b-deducing-this.cpp | 10 ++++++++++
2 files changed, 12 insertions(+)
diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp
index 473eea55bb6b19..0e932a1436d6e0 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -253,6 +253,8 @@ static void diagnoseInstanceReference(Sema &SemaRef,
SemaRef.Diag(Loc, diag::err_member_call_without_object)
<< Range << /*static*/ 0;
else {
+ if (auto *Tpl = dyn_cast<FunctionTemplateDecl>(Rep))
+ Rep = Tpl->getTemplatedDecl();
const auto *Callee = dyn_cast<CXXMethodDecl>(Rep);
auto Diag = SemaRef.Diag(Loc, diag::err_member_call_without_object)
<< Range << Callee->isExplicitObjectMemberFunction();
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index 0033541fa322dc..aab35828096a8e 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -626,3 +626,13 @@ void test() {
}
}
+
+
+namespace GH75732 {
+auto serialize(auto&& archive, auto&& c){ }
+struct D {
+ auto serialize(this auto&& self, auto&& archive) {
+ serialize(archive, self); // expected-error {{call to explicit member function without an object argument}}
+ }
+};
+}
>From b4c0760974034cdd035f06a597cfe8ae9423d043 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Tue, 19 Dec 2023 11:02:06 +0100
Subject: [PATCH 2/3] use cast instead of dyn_cast
---
clang/lib/Sema/SemaExprMember.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp
index 0e932a1436d6e0..11bfac1ecbf83c 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -255,7 +255,7 @@ static void diagnoseInstanceReference(Sema &SemaRef,
else {
if (auto *Tpl = dyn_cast<FunctionTemplateDecl>(Rep))
Rep = Tpl->getTemplatedDecl();
- const auto *Callee = dyn_cast<CXXMethodDecl>(Rep);
+ const auto *Callee = cast<CXXMethodDecl>(Rep);
auto Diag = SemaRef.Diag(Loc, diag::err_member_call_without_object)
<< Range << Callee->isExplicitObjectMemberFunction();
if (!Replacement.empty())
>From 9231e798f7878190eb3333a1194552f6e168bf3f Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Tue, 19 Dec 2023 18:21:55 +0100
Subject: [PATCH 3/3] add a const
---
clang/lib/Sema/SemaExprMember.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp
index 11bfac1ecbf83c..2abec3d86a27d9 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -253,7 +253,7 @@ static void diagnoseInstanceReference(Sema &SemaRef,
SemaRef.Diag(Loc, diag::err_member_call_without_object)
<< Range << /*static*/ 0;
else {
- if (auto *Tpl = dyn_cast<FunctionTemplateDecl>(Rep))
+ if (const auto *Tpl = dyn_cast<FunctionTemplateDecl>(Rep))
Rep = Tpl->getTemplatedDecl();
const auto *Callee = cast<CXXMethodDecl>(Rep);
auto Diag = SemaRef.Diag(Loc, diag::err_member_call_without_object)
More information about the cfe-commits
mailing list