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

    <tr>
        <th>Summary</th>
        <td>
            Clang assertion failure in range based for loop
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            c++20,
            clang:frontend,
            crash-on-invalid
      </td>
    </tr>

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

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

<pre>
    GCC: `g++.dg/cpp2a/range-for7.C`
```cpp
void foo(int n) {
    int a[] = {1, 2, 3, 4, 5};
    for (auto x = n ? 1 : 2 : a);
    for (int i = 1; auto x = n ? 1 : 2 : a);
}
```
Assertion failure: https://godbolt.org/z/M15Kz458W
```
#0 0x00005589e1d0330f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bb530f)
 #1 0x00005589e1d0107c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bb307c)
 #2 0x00005589e1c4a788 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007fa3ae4ee420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007fa3adfbb00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007fa3adf9a859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007fa3adf9a729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007fa3adfabfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x00005589e44cbd34 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x637dd34)
 #9 0x00005589e452f1d7 clang::Parser::ParseForStatement(clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x63e11d7)
#10 0x00005589e452a410 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x63dc410)
#11 0x00005589e452b845 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x63dd845)
#12 0x00005589e452c82a clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x63de82a)
#13 0x00005589e452e22a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x63e022a)
#14 0x00005589e4459891 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x630b891)
#15 0x00005589e447ffd0 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6331fd0)
#16 0x00005589e444d151 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62ff151)
#17 0x00005589e444da0f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#18 0x00005589e44543d1 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x63063d1)
#19 0x00005589e4454d03 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6306d03)
#20 0x00005589e44551e4 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x63071e4)
#21 0x00005589e4448aaa clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x62faaaa)
#22 0x00005589e2f4d8f8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4dff8f8)
#23 0x00005589e27a7329 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4659329)
#24 0x00005589e272c2c6 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45de2c6)
#25 0x00005589e288a1a6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x473c1a6)
#26 0x00005589df1c8f5c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x107af5c)
#27 0x00005589df1c4c7a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#28 0x00005589e25931fd 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
#29 0x00005589e1c4ac90 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3afcc90)
#30 0x00005589e2593a7f 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
#31 0x00005589e255b07c clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x440d07c)
#32 0x00005589e255bb0d 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+++0x440db0d)
#33 0x00005589e2563bed clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4415bed)
#34 0x00005589df1c71da clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x10791da)
#35 0x00005589df0ce215 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xf80215)
#36 0x00007fa3adf9c083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#37 0x00005589df1bfa5e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1071a5e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWlFz46oV_jXkhbEHAZLQgx8c53qb7d7ZO5tM--hBgBy6slARynXur-8gyY5QbG9uG-902pldxxZwznc-Pg4HSbxp9LZSagHiWxDf3fDWPRm7aJt9Ft_kRr4sPq1WgCwhSNAW4FuAb-dyC_Ba1DXmAK8tr7ZqVhibzlcgQQDdAbT0X7p_oq77K89GS1gYAzDTlYMVwBkE6W3fCCGE_irvQUBA7nxjBPAKYv9B_Af1HzFI7wAZjSuMhQ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