<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/122479>122479</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Clang] Crash involving lambda in unevaluated context and initialization of a static constexpr member of a class template
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          MagentaTreehouse
      </td>
    </tr>
</table>

<pre>
    The following C++20 code causes a crash:
```c++
template <class F = decltype([] {})>
struct A {
    F funcObj;
};

template <int>
struct B {
 static constexpr auto f{A{}.funcObj};
};

int main() {
 B<0>::f;
}
```

See https://compiler-explorer.com/z/caoTTePx1.

Assertion:
```console
clang++: /root/llvm-project/clang/lib/Sema/SemaDecl.cpp:16395:
clang::Decl* clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool):
Assertion `!Cleanup.exprNeedsCleanups() && "Unaccounted cleanups in function"' failed.
```

<details>

<Summary>Stack dump</summary>

```console
0.      Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 <source>
1.      <eof> parser at end of file
2.      <source>:11:12: parsing function body 'main'
 #0 0x0000000003c905f8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c905f8)
 #1 0x0000000003c8e304 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c8e304)
 #2 0x0000000003bda5f8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007feddc842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007feddc8969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007feddc842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007feddc8287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007feddc82871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007feddc839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x00000000069dcd2b clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x69dcd2b)
#10 0x00000000067367ef clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x67367ef)
#11 0x0000000006648bb3 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6648bb3)
#12 0x000000000667d68d clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x667d68d)
#13 0x000000000663c91e clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x663c91e)
#14 0x000000000663d0d9 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x663d0d9)
#15 0x0000000006644883 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6644883)
#16 0x000000000664575d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x664575d)
#17 0x0000000006637bba clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6637bba)
#18 0x000000000461eed8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x461eed8)
#19 0x00000000048dca59 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48dca59)
#20 0x000000000485f0be clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x485f0be)
#21 0x00000000049c9d1e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49c9d1e)
#22 0x0000000000cef5af cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcef5af)
#23 0x0000000000ce707a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#24 0x0000000004664cd9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#25 0x0000000003bdaaa4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bdaaa4)
#26 0x00000000046652cf clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#27 0x0000000004628c8d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4628c8d)
#28 0x0000000004629d0e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4629d0e)
#29 0x0000000004631475 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4631475)
#30 0x0000000000cec403 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcec403)
#31 0x0000000000bb7bd4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbb7bd4)
#32 0x00007feddc829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#33 0x00007feddc829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#34 0x0000000000ce6b25 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xce6b25)
```

</details>


See also #122419.

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzkWl1z46jS_jXkhrJLRt8XuVCc8b6zNfvO1Djn3LoQIIcdBDqAss7--lOAHEl24tlUxXNzpmYmCupunn5omgaEjeF7ydgtSO9Aen-De_uo9O0feM-kxQ-asUfVG3ZTK_p8-_DIYKOEUH9xuYdrgO4AukMRJIoySHBvmIEYEo3NI4grEFUgi8JfEmRBVFnWdgJbBkG8JgIbAzcQxPeQMiLsc8cAKgIUCPI7kN8DVIL4E4gqY3VPLKx8e1RBCOEGNr0kX-s_QeyanHR4mHfDpZ2ZuDuaMBZbTiBR0lh26DTEvVWwAfldFTpfHu2_WJ50waWFLebSIUbl0eYdiNeR6y6uQFw1o9qEjaC_Z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