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

    <tr>
        <th>Summary</th>
        <td>
            crash with lines and `CompactNamespaces: true NamespaceIndentation: All`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Hi,

I've had this issue for several versions of clang-format.
Currently using
```
▶ clang-format --version           
clang-format version 13.0.1

▶ clang --version                  
clang version 13.0.1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```

I tried to make a minimal example where I have the issue:
Given the source code in attached test.txt (I can't attach something with .hpp or something more cpp like)
and using a `.clang-format` file with following settings:
```
CompactNamespaces: true
NamespaceIndentation: All
```

if I then run
`clang-format --lines=1:1 test.txt`

then I get the following report:

```
/tmp   
▶ clang-format --lines=1:1 test.txt
/usr/include/c++/11.2.0/bits/stl_vector.h:1045: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::reference = int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]: Assertion '__n < this->size()' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.      Program arguments: clang-format --lines=1:1 test.txt
 #0 0x00007f99660cdfda (/usr/lib/libLLVM-13.so+0xb97fda)
 #1 0x00007f99660cb65f llvm::sys::RunSignalHandlers() (/usr/lib/libLLVM-13.so+0xb9565f)
 #2 0x00007f99660cb7ad (/usr/lib/libLLVM-13.so+0xb957ad)
 #3 0x00007f99651318e0 (/usr/lib/libc.so.6+0x3e8e0)
 #4 0x00007f996518136c (/usr/lib/libc.so.6+0x8e36c)
 #5 0x00007f9965131838 gsignal (/usr/lib/libc.so.6+0x3e838)
 #6 0x00007f996511b535 abort (/usr/lib/libc.so.6+0x28535)
 #7 0x00007f996c6fa23a (/usr/lib/libclang-cpp.so.13+0x8ea23a)
 #8 0x00007f996e387b6a clang::format::UnwrappedLineFormatter::format(llvm::SmallVectorImpl<clang::format::AnnotatedLine*> const&, bool, int, bool, unsigned int, unsigned int, unsigned int) (/usr/lib/libclang-cpp.so.13+0x2577b6a)
 #9 0x00007f996e389512 (/usr/lib/libclang-cpp.so.13+0x2579512)
#10 0x00007f996e37fd68 clang::format::TokenAnalyzer::process() (/usr/lib/libclang-cpp.so.13+0x256fd68)
#11 0x00007f996e5274e8 (/usr/lib/libclang-cpp.so.13+0x27174e8)
#12 0x00007f996e33b36c (/usr/lib/libclang-cpp.so.13+0x252b36c)
#13 0x00007f996e380b01 clang::format::internal::reformat(clang::format::FormatStyle const&, llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, unsigned int, unsigned int, unsigned int, llvm::StringRef, clang::format::FormattingAttemptStatus*) (/usr/lib/libclang-cpp.so.13+0x2570b01)
#14 0x00007f996e38189d clang::format::reformat(clang::format::FormatStyle const&, llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, llvm::StringRef, clang::format::FormattingAttemptStatus*) (/usr/lib/libclang-cpp.so.13+0x257189d)
#15 0x000055a84f036c4d (/usr/bin/clang-format+0xcc4d)
#16 0x000055a84f030d48 (/usr/bin/clang-format+0x6d48)
#17 0x00007f996511c290 (/usr/lib/libc.so.6+0x29290)
#18 0x00007f996511c34a __libc_start_main (/usr/lib/libc.so.6+0x2934a)
#19 0x000055a84f031245 (/usr/bin/clang-format+0x7245)
[1]    28064 IOT instruction (core dumped)  clang-format --lines=1:1 test.txt
```

[test.txt](https://github.com/llvm/llvm-project/files/9032866/test.txt)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNV8ty4jgU_RrYqKBsGRt7wYK8plOVeVQn01tKtgV4Ij9KkpPQXz9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