<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/163355>163355</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-format] Crash when using AllowShortNamespacesOnASingleLine with AlignAfterOpenBracket: BlockIndent
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
marco-antognini-sonarsource
</td>
</tr>
</table>
<pre>
The following code crashes:
```cpp
namespace {
void xxxxxxxxxxxxxxxxxxxxx(nnnnn::TTTTTTTTTTTTT const *mmmm,
YYYYYYYYYYYYYYYYY &yyyyyyyyyyyyyy);
} //
```
```shell
clang-format \
--style="{ColumnLimit: 120, AllowShortNamespacesOnASingleLine: true, AlignAfterOpenBracket: BlockIndent}" \
reproducer.cpp
```
In release with assertion, I get this assertion violation
```
Assertion failed: (LBrace && LBrace->is(tok::l_brace)), function isBlockIndentedInitRBrace, file FormatToken.cpp, line 74.
```
<details><summary>Stacktrace</summary>
<p>
```
0 libLLVMSupport.dylib 0x00000001012cf7e0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 libLLVMSupport.dylib 0x00000001012cd290 llvm::sys::RunSignalHandlers() + 172
2 libLLVMSupport.dylib 0x00000001012d02c8 SignalHandler(int, __siginfo*, void*) + 344
3 libsystem_platform.dylib 0x000000018f7a96a4 _sigtramp + 56
4 libsystem_pthread.dylib 0x000000018f76f848 pthread_kill + 296
5 libsystem_c.dylib 0x000000018f6789e4 abort + 124
6 libsystem_c.dylib 0x000000018f677c18 err + 0
7 libclangFormat.dylib 0x000000010081fd20 clang::format::CommaSeparatedList::formatAfterToken(clang::format::LineState&, clang::format::ContinuationIndenter*, bool) (.cold.1) + 0
8 libclangFormat.dylib 0x00000001007beb14 clang::format::FormatToken::opensBlockOrBlockTypeList(clang::format::FormatStyle const&) const + 0
9 libclangFormat.dylib 0x000000010078b644 clang::format::ContinuationIndenter::mustBreak(clang::format::LineState const&) + 580
10 libclangFormat.dylib 0x00000001007fb428 clang::format::(anonymous namespace)::OptimizingLineFormatter::addNextStateToQueue(unsigned int, clang::format::(anonymous namespace)::OptimizingLineFormatter::StateNode*, bool, unsigned int*, std::__1::priority_queue<std::__1::pair<std::__1::pair<unsigned int, unsigned int>, clang::format::(anonymous namespace)::OptimizingLineFormatter::StateNode*>, llvm::SmallVector<std::__1::pair<std::__1::pair<unsigned int, unsigned int>, clang::format::(anonymous namespace)::OptimizingLineFormatter::StateNode*>, 3u>, std::__1::greater<std::__1::pair<std::__1::pair<unsigned int, unsigned int>, clang::format::(anonymous namespace)::OptimizingLineFormatter::StateNode*>>>*) + 96
11 libclangFormat.dylib 0x00000001007fa948 clang::format::(anonymous namespace)::OptimizingLineFormatter::analyzeSolutionSpace(clang::format::LineState&, bool) + 1472
12 libclangFormat.dylib 0x00000001007f7024 clang::format::UnwrappedLineFormatter::format(llvm::SmallVectorImpl<clang::format::AnnotatedLine*> const&, bool, int, bool, unsigned int, unsigned int, unsigned int) + 1728
13 libclangFormat.dylib 0x00000001007a7558 clang::format::(anonymous namespace)::Formatter::analyze(clang::format::TokenAnnotator&, llvm::SmallVectorImpl<clang::format::AnnotatedLine*>&, clang::format::FormatTokenLexer&) + 556
14 libclangFormat.dylib 0x00000001007e13c0 clang::format::TokenAnalyzer::process(bool) + 1376
15 libclangFormat.dylib 0x00000001007bddc0 std::__1::__function::__func<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*)::$_12, std::__1::allocator<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*)::$_12>, std::__1::pair<clang::tooling::Replacements, unsigned int> (clang::format::Environment const&)>::operator()(clang::format::Environment const&) + 112
16 libclangFormat.dylib 0x000000010079fc4c 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*) + 1948
17 libclangFormat.dylib 0x00000001007a0bcc clang::format::reformat(clang::format::FormatStyle const&, llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, llvm::StringRef, clang::format::FormattingAttemptStatus*) + 52
18 clang-format 0x000000010062d360 clang::format::format(llvm::StringRef, bool) + 5172
19 clang-format 0x000000010062b1f8 main + 2024
20 dyld 0x000000018f3ceb98 start + 6076
```
</p>
</details>
Tested with current main (3793e75b7af7).
Bisection shows the bug was introduced in https://github.com/llvm/llvm-project/commit/083f099a345f02390d00a8196d4ffa36ae71c82f, i.e., the commit that introduced `AllowShortNamespacesOnASingleLine` from https://github.com/llvm/llvm-project/pull/123010.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWU1v4zjS_jX0hYhBUd8HH2R3B2-AvN277ewAezJoqWRzQ5Fakkra8-sXJJVYTuxuZzCzmAWGEGB9kFVPPSxWVSrMGL6TAAuULlH6acYGu1d60TFdqxsmrdpJLvmNUZJpowZdw2yrmsPiYQ-4VUKoZy53uFYN4FozsweD4goRf2UkXHXfI1JJ1oHpWQ0Y5UtEqifFG_z93EC0kG44SXH1MB24VtJYjGjVdV2H6AqRCv_z7cCIZoeTgWiJYqcV5Z8worfumiB8A9jsQQhEqlowubtple6YxSj1yvDNjbEHASj-hChF-XKlxNDJe95xi-IKR5QgusKVo2a9V9p-ebHbfJXVmsudgHsuwc21eoAwme9k1VrQX3uQS83qR_DClkLVj3eyAWlR7vS9otDQa9UMNeh5oPeNLXcSaxDADOBnbveYGQPaciWdvju8A4vtnpvje_zElWB-xikZiFTV66SWcQGNg4Zoce-QgiMb0QyHpxsUf-YG0cKqx7B_YrN1H9wOuGuF20HWXhg3E_uguZPcfluGuSv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