Skip to content

Commit a139f84

Browse files
authored
[Clang][Sema] fix assertion failure about invalid conversion when calling lambda (llvm#96431)
fixes llvm#96205 The cause is that some `Conversions[ConvIdx]` here is not initialized https://github.com/llvm/llvm-project/blob/eb76bc38ffc286e62fdb8f8d897b5de04b2575be/clang/lib/Sema/SemaOverload.cpp#L7888-L7901 and we do not check whether `Cand->Conversions[I]` is initialized or not here. https://github.com/llvm/llvm-project/blob/eb76bc38ffc286e62fdb8f8d897b5de04b2575be/clang/lib/Sema/SemaOverload.cpp#L12148-L12158
1 parent 5b89aaa commit a139f84

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,7 @@ Bug Fixes to C++ Support
935935
- Fix an assertion failure caused by parsing a lambda used as a default argument for the value of a
936936
forward-declared class. (#GH93512).
937937
- Fixed a bug in access checking inside return-type-requirement of compound requirements. (#GH93788).
938+
- Fixed an assertion failure about invalid conversion when calling lambda. (#GH96205).
938939

939940
Bug Fixes to AST Handling
940941
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaOverload.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12169,7 +12169,7 @@ static void NoteFunctionCandidate(Sema &S, OverloadCandidate *Cand,
1216912169
case ovl_fail_bad_conversion: {
1217012170
unsigned I = (Cand->IgnoreObjectArgument ? 1 : 0);
1217112171
for (unsigned N = Cand->Conversions.size(); I != N; ++I)
12172-
if (Cand->Conversions[I].isBad())
12172+
if (Cand->Conversions[I].isInitialized() && Cand->Conversions[I].isBad())
1217312173
return DiagnoseBadConversion(S, Cand, I, TakingCandidateAddress);
1217412174

1217512175
// FIXME: this currently happens when we're called from SemaInit

clang/test/SemaCXX/lambda-call.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %clang_cc1 -std=c++23 -verify -fsyntax-only %s
2+
3+
namespace GH96205 {
4+
5+
void f() {
6+
auto l = [](this auto& self, int) -> void { self("j"); }; // expected-error {{no matching function for call to object of type}} \
7+
// expected-note {{no known conversion from 'const char[2]' to 'int'}}
8+
l(3); // expected-note {{requested here}}
9+
}
10+
11+
}

0 commit comments

Comments
 (0)