[clang] Diag mismatch 97878 (PR #99824)

Braden Helmer via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 21 12:38:23 PDT 2024


https://github.com/bradenhelmer created https://github.com/llvm/llvm-project/pull/99824

Fixes #97878 

>From e4c3701ea6be894b1094f45d0590c61e5aa44897 Mon Sep 17 00:00:00 2001
From: Braden Helmer <bradenhelmeraus at gmail.com>
Date: Sun, 21 Jul 2024 14:10:17 -0400
Subject: [PATCH 1/2] Fix diag mismatch

---
 clang/lib/Sema/SemaOverload.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 5ea6b06121c7c..102cb5f7baef2 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -11152,7 +11152,8 @@ static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand,
   // non-constructor method.  Note that 'I' corresponds the
   // conversion-slot index.
   bool isObjectArgument = false;
-  if (isa<CXXMethodDecl>(Fn) && !isa<CXXConstructorDecl>(Fn)) {
+  if (isa<CXXMethodDecl>(Fn) && !isa<CXXConstructorDecl>(Fn) &&
+      !Fn->hasCXXExplicitFunctionObjectParameter()) {
     if (I == 0)
       isObjectArgument = true;
     else

>From 7f15d3d1a58f11c0ec2b6e646131c0fc0b7a9d5b Mon Sep 17 00:00:00 2001
From: Braden Helmer <bradenhelmeraus at gmail.com>
Date: Sun, 21 Jul 2024 15:37:09 -0400
Subject: [PATCH 2/2] Small change and add test

---
 clang/lib/Sema/SemaOverload.cpp            | 5 ++---
 clang/test/SemaCXX/cxx2b-deducing-this.cpp | 8 ++++++++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 1ef43b2103a9b..ac90ccd5643c1 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -11146,11 +11146,10 @@ static void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand,
   // non-constructor method.  Note that 'I' corresponds the
   // conversion-slot index.
   bool isObjectArgument = false;
-  if (isa<CXXMethodDecl>(Fn) && !isa<CXXConstructorDecl>(Fn) &&
-      !Fn->hasCXXExplicitFunctionObjectParameter()) {
+  if (isa<CXXMethodDecl>(Fn) && !isa<CXXConstructorDecl>(Fn)) {
     if (I == 0)
       isObjectArgument = true;
-    else
+    else if (!Fn->hasCXXExplicitFunctionObjectParameter())
       I--;
   }
 
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index 5cbc1f735383b..6ad54b9b2c63d 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -959,3 +959,11 @@ void f();
 };
 void a::f(this auto) {} // expected-error {{an explicit object parameter cannot appear in a non-member function}}
 }
+
+struct R {
+  void f(this auto &&self, int &&r_value_ref) {} // expected-note {{candidate function template not viable: expects an rvalue for 2nd argument}}
+  void g(int &&r_value_ref) {
+	f(r_value_ref); // expected-error {{no matching member function for call to 'f'}}
+  }
+};
+



More information about the cfe-commits mailing list