diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index f0cdccfcc3c23..594e053af02da 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -818,6 +818,7 @@ Bug Fixes to C++ Support Fixes (`#80252 `_) - Fix a regression introduced in Clang 18 causing incorrect overload resolution in the presence of functions only differering by their constraints when only one of these function was variadic. +- Fix a crash when a variable is captured by a block nested inside a lambda. (Fixes #GH93625). Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 41fbfe281ef65..0a35ed536a6a7 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -2408,9 +2408,11 @@ Expr *VarDecl::getInit() { return cast(S); auto *Eval = getEvaluatedStmt(); - return cast(Eval->Value.isOffset() - ? Eval->Value.get(getASTContext().getExternalSource()) - : Eval->Value.get(nullptr)); + + return cast_if_present( + Eval->Value.isOffset() + ? Eval->Value.get(getASTContext().getExternalSource()) + : Eval->Value.get(nullptr)); } Stmt **VarDecl::getInitAddress() { diff --git a/clang/test/SemaObjCXX/block-capture.mm b/clang/test/SemaObjCXX/block-capture.mm index 8ba02f919e015..231aef33f2c7e 100644 --- a/clang/test/SemaObjCXX/block-capture.mm +++ b/clang/test/SemaObjCXX/block-capture.mm @@ -83,3 +83,21 @@ SubMove(SubSubMove &&); }; TEST(SubMove); + + +#if __cplusplus >= 202302L +// clang used to crash compiling this code. +namespace BlockInLambda { + struct S { + constexpr ~S(); + }; + + void func(S const &a) { + [a](auto b) { + ^{ + (void)a; + }(); + }(12); + } +} +#endif