<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60145>60145</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-format] legacy code using import:: as a namespace causes a recently introduced crash
</td>
</tr>
<tr>
<th>Labels</th>
<td>
bug,
clang-format,
regression,
crash,
crash-on-valid
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mydeveloperday
</td>
</tr>
</table>
<pre>
Found whilst testing the latest 16.0 clang-format against large previously 100% clang-formatted legacy code base.
(issue does not occur on 15.0.0 -> 15.0.7)
Not that I would normally expect clang-format to handle a keyword where it was used as an identifier, I'm not sure it should crash especially on the introduction of a keyword that hasn't always been around (pre c++20).
(note it seems the conditional val ? 2 : 1 is important too in order to see the crash.
clang-format -n test.cpp
(test.cpp)
```c++
void Foo::Bar() { import::Bar foo(val ? 2 : 1); }
```
clang-format version 16.0.0 (https://github.com/llvm/llvm-project.git 658bf08f67
d50ae0babd2d2b1e4f8c93d50c3f1d)
```
Assertion failed: (!TypeIsFinalized || T == Type) && "Please use overwriteFixedType to change a fixed type.", file c:\llvm\llvm-project\clang\lib\Format\FormatToken.h, line 377
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: C:\\cygwin64\\buildareas\\llvm3\\build_ninja\\bin\\clang-format.exe -n 6a.cpp
Exception Code: 0x80000003
#0 0x00007ff76254959c HandleAbort c:\llvm\llvm-project\llvm\lib\Support\Windows\Signals.inc:415:0
#1 0x00007ff9ae1190ed (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xa90ed)
#2 0x00007ff9ae11ae49 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xaae49)
#3 0x00007ff9ae120c6f (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xb0c6f)
#4 0x00007ff9ae11eba1 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xaeba1)
#5 0x00007ff9ae1218af (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xb18af)
#6 0x00007ff7626ff778 clang::format::FormatToken::setType(enum clang::format::TokenType) c:\llvm\llvm-project\clang\lib\Format\FormatToken.h:376:0
#7 0x00007ff7626e16dc clang::format::`anonymous namespace'::AnnotatingParser::parseConditional c:\llvm\llvm-project\clang\lib\Format\TokenAnnotator.cpp:915:0
#8 0x00007ff7626e301f clang::format::`anonymous namespace'::AnnotatingParser::consumeToken c:\llvm\llvm-project\clang\lib\Format\TokenAnnotator.cpp:1248:0
#9 0x00007ff7626dfbba clang::format::`anonymous namespace'::AnnotatingParser::parseParens c:\llvm\llvm-project\clang\lib\Format\TokenAnnotator.cpp:517:0
#10 0x00007ff7626e2745 clang::format::`anonymous namespace'::AnnotatingParser::consumeToken c:\llvm\llvm-project\clang\lib\Format\TokenAnnotator.cpp:1128:0
#11 0x00007ff7626e4269 clang::format::`anonymous namespace'::AnnotatingParser::parseLine c:\llvm\llvm-project\clang\lib\Format\TokenAnnotator.cpp:1528:0
#12 0x00007ff7626d2acc clang::format::TokenAnnotator::annotate(class clang::format::AnnotatedLine &) const c:\llvm\llvm-project\clang\lib\Format\TokenAnnotator.cpp:2771:0
#13 0x00007ff762734320 clang::format::TokenAnalyzer::process(bool) c:\llvm\llvm-project\clang\lib\Format\TokenAnalyzer.cpp:127:0
#14 0x00007ff762678566 <lambda_17740737aea18d5c1e4c481f38a62347>::operator() c:\llvm\llvm-project\clang\lib\Format\Format.cpp:3479:0
#15 0x00007ff76269d298 std::invoke<<lambda_17740737aea18d5c1e4c481f38a62347> &,clang::format::Environment const &> C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\type_traits:1595:0
#16 0x00007ff762687aa8 std::_Invoker_ret<std::pair<clang::tooling::Replacements,unsigned int>,0>::_Call<<lambda_17740737aea18d5c1e4c481f38a62347> &,clang::format::Environment const &> C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\functional:753:0
#17 0x00007ff76267a417 std::_Func_impl_no_alloc<<lambda_17740737aea18d5c1e4c481f38a62347>,std::pair<clang::tooling::Replacements,unsigned int>,clang::format::Environment const &>::_Do_call C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\functional:920:0
#18 0x00007ff7626bc8fc std::_Func_class<struct std::pair<class clang::tooling::Replacements, unsigned int>, class clang::format::Environment const &>::operator()(class clang::format::Environment const &) const C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\functional:968:0
#19 0x00007ff76266c6d0 clang::format::internal::reformat(struct clang::format::FormatStyle const &, class llvm::StringRef, class llvm::ArrayRef<class clang::tooling::Range>, unsigned int, unsigned int, unsigned int, class llvm::StringRef, struct clang::format::FormattingAttemptStatus *) c:\llvm\llvm-project\clang\lib\Format\Format.cpp:3519:0
#20 0x00007ff7626693d9 clang::format::reformat(struct clang::format::FormatStyle const &, class llvm::StringRef, class llvm::ArrayRef<class clang::tooling::Range>, class llvm::StringRef, struct clang::format::FormattingAttemptStatus *) c:\llvm\llvm-project\clang\lib\Format\Format.cpp:3544:0
#21 0x00007ff76241ceeb clang::format::format c:\llvm\llvm-project\clang\tools\clang-format\ClangFormat.cpp:500:0
#22 0x00007ff76241e657 main c:\llvm\llvm-project\clang\tools\clang-format\ClangFormat.cpp:632:0
#23 0x00007ff7629a5ad9 invoke_main d:\a01\_work\12\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:79:0
#24 0x00007ff7629a59be __scrt_common_main_seh d:\a01\_work\12\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288:0
#25 0x00007ff7629a587e __scrt_common_main d:\a01\_work\12\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:331:0
#26 0x00007ff7629a5b6e mainCRTStartup d:\a01\_work\12\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:17:0
#27 0x00007ffa14087614 (C:\WINDOWS\System32\KERNEL32.DLL+0x17614)
#28 0x00007ffa153226a1 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x526a1)
```
conversely, renaming the namespace it works fine
```c++
void Foo::Bar() { imp::Bar foo(val ? 2 : 1); }
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWV9v4zYS_zTMCxFDIvX3IQ-OEuMWt-0tNosW92RQ5MhmQ5MGSTlxP_2BlO1YapLdpCnQ3mIRixQ585s_nBlxmHNypQGuUH6N8psL1vu1sVebvYAdKLMFK9j-ojVif7UwvRb4YS2V89iD81KvsF8DViyMcFrMEswV06vLztgN85itmNTOY8XsCvDWwk6a3qk9TpMEkXy02IPAClaM7zE3AnDLHMxQcoOSOSKVdK4HLAw4rI3HhvPeYqNxms-SWYIvEb0dnktE6sOu-Pdn47FfM48_4QfTK4F14KbUHsPjFrgfA_YGr5kWCjDD97B_MDYIDBaw9PiBOdw7EJg5zDSWArSXnQSLSIM_IVJuIjbXD8vdOvLjlrk1BrcFLiNfo6PSpPbWiJ57aTQ23RnDCHfNnEak9JipB7Z3uAXQmNloAkSqrQXMEblG5JokiNSzc5kRqbTxAwiAjYv8uNFCBmZM4R1TGNEFJhjROU6xdFhutsZ6poMODJYaGyvABoU4gIFAEGTEZ6S6Sx19Ysa32wmW0_TJMkUy_D9IMMzujBR4YQyic0Tn18wiUiFSY1ReH9Cd3uDOGESqiRiBPr3GqLyZsHkG7Q6sC4oPPjtLgkbX3m9d4EAWiCxW0q_7dsbNBpGFUrvjz-XWmt-A-9lKelzkVdslVVeUAweRJwySlrWCCNKmkHUVr6nIE067VEwcc4Ju7hzY6AsdkwpEkCgqIP2238Int5CaKfk7CIzKBpUN_oYRvUH0Bof3UU-kQKTAiJAvCpiD4KvY7MA-WOlhIR9BhKXBpHzN9Cr4eBdmsd9vYYYICX7cSRU8i85R3kS5h5-j3Chvoh7DtGxR3iyiPk8P38w96Nk6UFJSA6blQTdfP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