[clang] [Clang][Sema] fix assertion failure about invalid conversion when calling lambda (PR #96431)

Zhikai Zeng via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 28 07:27:36 PDT 2024


https://github.com/Backl1ght updated https://github.com/llvm/llvm-project/pull/96431

>From ce317e4c2f1bca3e81b81ac8909c576b14a16a6b Mon Sep 17 00:00:00 2001
From: Backl1ght <backlight.zzk at gmail.com>
Date: Sun, 23 Jun 2024 21:44:03 +0800
Subject: [PATCH] fix

---
 clang/docs/ReleaseNotes.rst        |  1 +
 clang/lib/Sema/SemaOverload.cpp    |  2 +-
 clang/test/SemaCXX/lambda-call.cpp | 11 +++++++++++
 3 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/lambda-call.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index da967fcdda808..feba3c7ba8d77 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -935,6 +935,7 @@ Bug Fixes to C++ Support
 - Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a
   forward-declared class. (#GH93512).
 - Fixed a bug in access checking inside return-type-requirement of compound requirements. (#GH93788).
+- Fixed an assertion failure about invalid conversion when calling lambda. (#GH96205).
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index ee921c825b2a4..f8f55ce6526ac 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -12169,7 +12169,7 @@ static void NoteFunctionCandidate(Sema &S, OverloadCandidate *Cand,
   case ovl_fail_bad_conversion: {
     unsigned I = (Cand->IgnoreObjectArgument ? 1 : 0);
     for (unsigned N = Cand->Conversions.size(); I != N; ++I)
-      if (Cand->Conversions[I].isBad())
+      if (Cand->Conversions[I].isInitialized() && Cand->Conversions[I].isBad())
         return DiagnoseBadConversion(S, Cand, I, TakingCandidateAddress);
 
     // FIXME: this currently happens when we're called from SemaInit
diff --git a/clang/test/SemaCXX/lambda-call.cpp b/clang/test/SemaCXX/lambda-call.cpp
new file mode 100644
index 0000000000000..2c5b8b9a4b176
--- /dev/null
+++ b/clang/test/SemaCXX/lambda-call.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -std=c++23 -verify -fsyntax-only %s
+
+namespace GH96205 {
+
+void f() {
+  auto l = [](this auto& self, int) -> void { self("j"); }; // expected-error {{no matching function for call to object of type}} \
+                                                            // expected-note {{no known conversion from 'const char[2]' to 'int'}}
+  l(3); // expected-note {{requested here}}
+}
+
+}



More information about the cfe-commits mailing list