Skip to content
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

[Clang] Fix a crash when incorrectly calling an explicit object member function template #75913

Merged
merged 3 commits into from
Dec 20, 2023

Conversation

cor3ntin
Copy link
Contributor

Fixes #75732

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Dec 19, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Dec 19, 2023

@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)

Changes

Fixes #75732


Full diff: https://github.com/llvm/llvm-project/pull/75913.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaExprMember.cpp (+2)
  • (modified) clang/test/SemaCXX/cxx2b-deducing-this.cpp (+10)
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}}
+    }
+};
+}

Copy link
Contributor

@Fznamznon Fznamznon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a little NIT

@@ -253,7 +253,9 @@ static void diagnoseInstanceReference(Sema &SemaRef,
SemaRef.Diag(Loc, diag::err_member_call_without_object)
<< Range << /*static*/ 0;
else {
const auto *Callee = dyn_cast<CXXMethodDecl>(Rep);
if (auto *Tpl = dyn_cast<FunctionTemplateDecl>(Rep))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a const can be added here.

@cor3ntin cor3ntin merged commit c853676 into llvm:main Dec 20, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clang - current trunk crashed when compiling the following code
5 participants