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

    <tr>
        <th>Summary</th>
        <td>
            [clang-format] Assertion failed in FormatToken.cpp
        </td>
    </tr>

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

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

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

<pre>
    I encountered a crash with clang-format 19.1.4 (well, initially with 19.1.0 before I tried the newer version).

I built a debug version and got the following output.
(Including the debug output as it seemed to have more information than the regular version that I initially encountered. E.g. it mentioned the assertion)

```
Assertion failed: i < MustBreakBeforeItem.size(), file \clang\lib\Format\FormatToken.cpp, line 271
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: clang-format.exe ./temp.C
Exception Code: 0x80000003
0x00007FF67CF7EF7C, clang-format.exe(0x00007FF67CDD0000) + 0x1AEF7C byte(s), HandleAbort() + 0xC byte(s), \llvm\lib\Support\Windows\Signals.inc, line 429 + 0x0 byte(s)
0x00007FF8E7B090ED, C:\WINDOWS\SYSTEM32\ucrtbased.dll(0x00007FF8E7A60000) + 0xA90ED byte(s), raise() + 0x46D byte(s)
0x00007FF8E7B0AE49, C:\WINDOWS\SYSTEM32\ucrtbased.dll(0x00007FF8E7A60000) + 0xAAE49 byte(s), abort() + 0x39 byte(s)
0x00007FF8E7B11345, C:\WINDOWS\SYSTEM32\ucrtbased.dll(0x00007FF8E7A60000) + 0xB1345 byte(s), _get_wide_winmain_command_line() + 0x2895 byte(s)
0x00007FF8E7B10BD7, C:\WINDOWS\SYSTEM32\ucrtbased.dll(0x00007FF8E7A60000) + 0xB0BD7 byte(s), _get_wide_winmain_command_line() + 0x2127 byte(s)
0x00007FF8E7B0EBA1, C:\WINDOWS\SYSTEM32\ucrtbased.dll(0x00007FF8E7A60000) + 0xAEBA1 byte(s), _get_wide_winmain_command_line() + 0xF1 byte(s)
0x00007FF8E7B118AF, C:\WINDOWS\SYSTEM32\ucrtbased.dll(0x00007FF8E7A60000) + 0xB18AF byte(s), _wassert() + 0x2F byte(s)
0x00007FF67D11B13E, clang-format.exe(0x00007FF67CDD0000) + 0x34B13E byte(s), clang::format::CommaSeparatedList::precomputeFormattingInfos() + 0x75E byte(s), \clang\lib\Format\FormatToken.cpp, line 271 + 0x40 byte(s)
0x00007FF67D120B18, clang-format.exe(0x00007FF67CDD0000) + 0x350B18 byte(s), clang::format::TokenAnnotator::calculateFormattingInformation() + 0xF08 byte(s), \clang\lib\Format\TokenAnnotator.cpp, line 4071 + 0x44 byte(s)
0x00007FF67D11FCA5, clang-format.exe(0x00007FF67CDD0000) + 0x34FCA5 byte(s), clang::format::TokenAnnotator::calculateFormattingInformation() + 0x95 byte(s), \clang\lib\Format\TokenAnnotator.cpp, line 3866 + 0x12 byte(s)
0x00007FF67D0B5D8E, clang-format.exe(0x00007FF67CDD0000) + 0x2E5D8E byte(s), clang::format::`anonymous namespace'::SemiRemover::removeSemi() + 0x10E byte(s), \clang\lib\Format\Format.cpp, line 2305 + 0x0 byte(s)
0x00007FF67D0B5C31, clang-format.exe(0x00007FF67CDD0000) + 0x2E5C31 byte(s), clang::format::`anonymous namespace'::SemiRemover::analyze() + 0x71 byte(s), \clang\lib\Format\Format.cpp, line 2282 + 0x19 byte(s)
0x00007FF67D1553D1, clang-format.exe(0x00007FF67CDD0000) + 0x3853D1 byte(s), clang::format::TokenAnalyzer::process() + 0x621 byte(s), \clang\lib\Format\TokenAnalyzer.cpp, line 129 + 0x4B byte(s)
0x00007FF67D0C142C, clang-format.exe(0x00007FF67CDD0000) + 0x2F142C byte(s), `clang::format::internal::reformat'::`36'::<lambda_5>::operator()() + 0x6C byte(s), \clang\lib\Format\Format.cpp, line 3716 + 0x3D byte(s)
0x00007FF67D0E5D18, clang-format.exe(0x00007FF67CDD0000) + 0x315D18 byte(s), std::invoke<`clang::format::internal::reformat'::`36'::<lambda_5> &,clang::format::Environment const &>() + 0x28 byte(s), C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.42.34433\include\type_traits, line 1705 + 0x14 byte(s)
0x00007FF67D0C35CF, clang-format.exe(0x00007FF67CDD0000) + 0x2F35CF byte(s), std::_Func_impl_no_alloc<`clang::format::internal::reformat'::`36'::<lambda_5>,std::pair<clang::tooling::Replacements,unsigned int>,clang::format::Environment const &>::_Do_call() + 0x2F byte(s), C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.42.34433\include\functional, line 876 + 0x1B byte(s)
0x00007FF67D10883E, clang-format.exe(0x00007FF67CDD0000) + 0x33883E byte(s), std::_Func_class<std::pair<clang::tooling::Replacements,unsigned int>,clang::format::Environment const &>::operator()() + 0x5E byte(s), C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.42.34433\include\functional, line 920 + 0x24 byte(s)
0x00007FF67D0C070D, clang-format.exe(0x00007FF67CDD0000) + 0x2F070D byte(s), clang::format::internal::reformat() + 0xD2D byte(s), \clang\lib\Format\Format.cpp, line 3768 + 0x4F byte(s)
0x00007FF67D0B1DC9, clang-format.exe(0x00007FF67CDD0000) + 0x2E1DC9 byte(s), clang::format::reformat() + 0xB9 byte(s), \clang\lib\Format\Format.cpp, line 3812 + 0x9C byte(s)
0x00007FF67CE22679, clang-format.exe(0x00007FF67CDD0000) + 0x52679 byte(s), clang::format::format() + 0x1789 byte(s), \clang\tools\clang-format\ClangFormat.cpp, line 510 + 0x1F2 byte(s)
0x00007FF67CE249DA, clang-format.exe(0x00007FF67CDD0000) + 0x549DA byte(s), main() + 0x81A byte(s), \clang\tools\clang-format\ClangFormat.cpp, line 734 + 0x88 byte(s)
0x00007FF67D4876C9, clang-format.exe(0x00007FF67CDD0000) + 0x6B76C9 byte(s), invoke_main() + 0x39 byte(s), D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl, line 79 + 0x0 byte(s)
0x00007FF67D4875B2, clang-format.exe(0x00007FF67CDD0000) + 0x6B75B2 byte(s), __scrt_common_main_seh() + 0x132 byte(s), D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl, line 288 + 0x5 byte(s)
0x00007FF67D48746E, clang-format.exe(0x00007FF67CDD0000) + 0x6B746E byte(s), __scrt_common_main() + 0xE byte(s), D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl, line 331 + 0x0 byte(s)
0x00007FF67D48775E, clang-format.exe(0x00007FF67CDD0000) + 0x6B775E byte(s), mainCRTStartup() + 0xE byte(s), D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp, line 17 + 0x0 byte(s)
0x00007FFA0C95259D, C:\WINDOWS\System32\KERNEL32.DLL(0x00007FFA0C940000) + 0x1259D byte(s), BaseThreadInitThunk() + 0x1D byte(s)
0x00007FFA0DC4AF38, C:\WINDOWS\SYSTEM32\ntdll.dll(0x00007FFA0DBF0000) + 0x5AF38 byte(s), RtlUserThreadStart() + 0x28 byte(s)
```

I managed to reduce the offending code to the following reproducible case:

```
void foo::bar()
{
  auto sgf = [&](const dimC& U)
  {
 std::array<Tfloat64, 39> ogl = {
        dimC::Mi() * 0.001,
 dimC::Mi() * 0.01,
        dimC::Mi() * 0.1,
        dimC::Mi() * 0.5,
        dimC::Mi(),
        dimC::Mi() * 5,
        dimC::Mi() * 10,
        dimC::Mi() * 50,
        dimC::Mi() * 100,
 dimC::Mi() * 500,
        dimC::T(),
        dimC::T() * 5,
 dimC::T() * 10,
        dimC::T() * 50,
        dimC::T() * 100,
 dimC::T() * 500,
        dimC::I(),
        dimC::I() * 6,
 dimC::F(),
        dimC::Y(),
        dimC::Y() * 4,
 dimC::Y() * 8,
        dimC::Y() * 8 * 4,
        dimC::Y() * 8 * 4 * 5,
        dimC::Y() * 8 * 8 * 5,
        dimC::Mi() / 2,
 dimC::Mi(),
        dimC::Mi() * 5,
        dimC::Mi() * 10,
 dimC::Mi() * 50,
        dimC::Mi() * 100,
        dimC::Mi() * 500,
        dimC::Mi() * 1000,
        dimC::Mi() * 5000,
 dimC::Mi() * 10000,
        dimC::Mi() * 50000,
        dimC::Mi() * 100000,
        dimC::Mi() * 500000,
        dimC::Mi() * 1000000,
 };
  };
}
```

I then tried it with the current main, but it also hit the assertion.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWl9z4ygS_zTkhVoVQkKSH_JgI6sudTN7W5Psbu2TC0vY5oLABSiZ7Ke_QrJsy078b7Oz55qa6E_3j-4fDXSDmLViqTi_B2QCSH7HGrfS5t7UzDxzczfX1dv9A-Sq1I1y3PAKMlgaZlfwVbgVLCVTy58W2tTMwXAUhEEMAc5euZQAUyiUcIJJ-dZJtwIIzvlCGw4foDOCV9CtOFT8lRv4wo0VWgE8CgDKARp3_z_AeSOkgwxWfN4sezHIVAWX2rUACy2lfhVqCXXj1o3rAXD2oErZVP6Nl-sQOhnILBQOWs5rb4aGK_bCYe1tE6rzyTfjVky1uoYvG8m2ZvoXDj7sOblHUwCnwTLw8DVXHmbjKLOWG9c5ue8jSNDmX3s77sXgggnJKxCNoYAgovBrY93EcPY8aVl8cLwOrPiTA5x5SEzhQkgOAaFt3wBCpZgDQovWn-3Fk37mKijXa68hheIQp2HX9i9fpuPHKbTNvBaedE-Y4WttXMuRc2sLojHABcDFUrhVMw9KXQNcSPnS__lpbfR_eekALoS1DbcAF21_ibY3eMtFF0dzVj47w0q-6bJHx8pnWDX12rfSPkIBbH-_GL00rIbMLBtPq7djEIIB_85hAHDheL0OaKc9_V7ydcsl1RX3Kuh7htpftMH_7m_SokhSWqTTIqWelUNggLN9wTz31wCPIMATiL6HY68I52_OS9pNZ_yLqUry8Vwb1_XQRvpI0HeU56_vr8dm7SkHhP4uVKVfrX8mlopJGwhVbrst3kKiAeTQsWyaTtAITXOvRz2xhP7-8HP-n98fPe4fj0_TrxEGhDalcXNmeRV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