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

    <tr>
        <th>Summary</th>
        <td>
            [clang-format] Crash when formatting nested namespaces with macro and comment before
        </td>
    </tr>

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

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

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

<pre>
    Very similar crash to #64701

Code:
```cpp
namespace aa { namespace bb {
Foo()
{
//comment
#ifdef DEF
#endif
}
}}
```

style settings:
```
Language: Cpp
BasedOnStyle: LLVM
CompactNamespaces: true
NamespaceIndentation: All
```

Error on the current 17.0.6 version.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8kk-PmzAQxT-NuYyCjPm3OXDYJItUKW0PlfZu4zG4Mjayza7y7SsgJK0qrYTA_tkzeo95PATdW8SGlCdSXhI-x8H5xiD6PhFO3pp39DcIetSGe-g8DwNEB4TlVVHTjNALoa_b--wkkvy-IRXdnm6aNmL5iGHiHQLnQOoTPIEQC9iutc4R9kLY8d5n54S1hLWdG0e0cUe5VhIVXN7aB0ErtdprL8_FY70L-1t6iDeDEDBGbfvwv4lte-W2n3m_mITzbuvEA8qf9tfSYTm4Xt-_7_9jnHgXf-w2l74Q_Yzb8YN_sxJt5FE7u9x4NeYLpW_eOw_OQhwQutl7tBGyOqVpBR_og3Y2TWSTy2N-5Ak2WU3LvCwqRpOhKaSqFFO8qnMlSoVFR-tSKFrwvDrSMk90wygraJaVLMtrSlPBSkVLWQiR17w6FqSgOHJtUmM-xtT5PtEhzNjULyxjieECTVizxFhnuO0PyvmRR8LYki7fLGUHMfeBFNToEMOzUdTRrDn8p7C8wHkN3eeAFja4DAkshojyGaIAnzoOMPLOO-BWwj0qIFA5j8nsTTPEOK3TXbPU6zjMIu3cSFi7yLh_DpN3v7GLhLWruUBYu_r7EwAA__-MA_N0">