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

    <tr>
        <th>Summary</th>
        <td>
            [clang-format] Crash when parsing requires clause
        </td>
    </tr>

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

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

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

<pre>
    `clang-format` crashes when trying to format the following (admittedly syntactically incorrect) code snippet
```
template <class T>
    requires(requires { std::declval<T>()
```
with the following call stack:
```
clang-format.exe!clang::format::UnwrappedLineParser::parseRequiresClause(clang::format::FormatToken * RequiresToken) Line 3636  C++
clang-format.exe!clang::format::UnwrappedLineParser::parseRequires() Line 3505  C++
clang-format.exe!clang::format::UnwrappedLineParser::parseStructuralElement(const clang::format::FormatToken * OpeningBrace,clang::format::UnwrappedLineParser::IfStmtKind * IfKind, clang::format::FormatToken * * IfLeftBrace, bool * HasDoWhile, bool * HasLabel) Line 1794  C++
clang-format.exe!clang::format::UnwrappedLineParser::parseLevel(const clang::format::FormatToken * OpeningBrace, clang::format::UnwrappedLineParser::IfStmtKind * IfKind,clang::format::FormatToken * * IfLeftBrace) Line 479   C++
clang-format.exe!clang::format::UnwrappedLineParser::parseFile() Line 289       C++
clang-format.exe!clang::format::UnwrappedLineParser::parse() Line 217   C++
clang-format.exe!clang::format::TokenAnalyzer::process(bool SkipAnnotation) Line 116    C++
[Inline Frame] clang-format.exe!clang::format::internal::reformat::__l39::<lambda_6>::operator()(const clang::format::Environment &) Line 3796        C++
[Inline Frame] clang-format.exe!std::invoke(clang::format::internal::reformat::__l39::<lambda_6> &) Line 1705 C++
clang-format.exe!std::_Func_impl_no_alloc<`clang::format::internal::reformat'::`39'::<lambda_6>,std::pair<clang::tooling::Replacements,unsigned int>clang::format::Environment const &>::_Do_call(const clang::format::Environment & <_Args_0>) Line 876      C++
[Inline Frame] clang-format.exe!std::_Func_class<std::pair<clang::tooling::Replacements,unsigned int>,clang::format::Environment const &>::operator()(constclang::format::Environment &) Line 920   C++
clang-format.exe!clang::format::internal::reformat(const clang::format::FormatStyle & Style, llvm::StringRef Code, llvm::ArrayRef<clang::tooling::Range> Ranges, unsignedint FirstStartColumn, unsigned int NextStartColumn, unsigned int LastStartColumn, llvm::StringRef FileName, clang::format::FormattingAttemptStatus * Status) Line 3843       ++
clang-format.exe!clang::format::reformat(const clang::format::FormatStyle & Style, llvm::StringRef Code, llvm::ArrayRef<clang::tooling::Range> Ranges, llvm::StringRefFileName, clang::format::FormattingAttemptStatus * Status) Line 3886    C++
clang-format.exe!clang::format::format(llvm::StringRef FileName, bool ErrorOnIncompleteFormat) Line 511 C++
clang-format.exe!main(int argc, const char * * argv) Line 738   C++
```
Happens in `main` as well as `19.1.x`, did not tried other versions.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMV01v2zgT_jX0hahBUdbXwQdHidHgDdoXSRd7NGhpLHNDkVpy5NT76xekbCdum8RxE2ABAx6R4syjZ4bzIZyTjQaYkuSCJJcj0ePa2KnQDtp7uRktTb2dkpRVSujm08rYViBJGa2scGtw9GENmqLdSt1QNHR4geIa6MooZR78OuG5qFuJCLXaUrfVKCqUlVBqS6WujLVQIeEFrUwN1GnZdYCEzUjKdj82Q2g7JRAoictKCefoNxJfETajlFILf_fSgiM834uUZBfUYU3iGYlnNVRqIxSJy3CK54QXPxh4kLj-AbdHSB2K6t5rOX79KR9j-A6ER2FpsLfjKch_6Acrug7qG6nh_8I6sMNG5-XbHd5Sid4B4fkzWuZB_mbuQVPCZ3R_Lqx47rx2GqdxSlhREn7hf-8Pc6BuZyxhyYcYu0PbV9hboa4UtKDR02K0Q3oiOV870FI3F1ZUQHj5VhDXqzts8X9S10Hb9cqLhJenmh8O3cAK9wjo0hgV1j8Ld2n-XEv10_KNWII6kBtlxeRDyL2BjTfzW4Q-d-zNjJ5L6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