<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/67992>67992</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang 17 incorrect order of static initialization with pch
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zlojvavan
</td>
</tr>
</table>
<pre>
first time clang user here so please bear with me. been using borland/codegear/embarcadero, msvc and gcc for years and recently decided to test clang just to discover incorrect order of static initializations in generated binary, but only with pch. msvc/gcc produce correct order with and without using of pch as well as clang without pch. I was able to find crazy workaround for my specific case and finally create working executable with clang and wonder whether it is known problem or not before trying to narrow down the bug in reduced test case.
Ubuntu clang version 17.0.2 (++20230929073225+098e653a5bed-1~exp1~20230929073241.48) here
basically, bug manifests itself as a class constructor running before its static inline members constructed BUT ONLY WITH PCH/clang combination.
...
#2 0x560ef541c218 in __cxx_global_var_init.17 /home/vavan/projects/lnsc/NetworkServer/lnsc/../../Common/helperCommonNew.h:13396:33
#3 0x7f85a4629eba in call_init csu/../csu/libc-start.c:145:3
#4 0x7f85a4629eba in __libc_start_main csu/../csu/libc-start.c:379:5
#5 0x560ef5334024 in _start (/home/vavan/projects/lnsc/bin/x64/Debug/lnsc.out+0xdeb024) (BuildId: 1d6ddc43d7bed932)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVEtv4zgT_DX0pRFBIvWwDj7YExgT4EO-BXYGiz0ZfLQkZijSICk_cpjfviDtTBJggdmLRNPd1dXVpeYh6NEibkizI83jii9xcn7zatzLiZ-4XQmnrptB-xAh6hlBGm5HWAJ6mNAjBAdHgzwgCOQezjpOMGMBAtHCErQdQThvuFWE7qVTOCL3hO5xFtxLrtA7Qr_AHE4SuFUwSgmD83BF7kO-8SjRRnMFhVIrVBAdRAzxTuVlSdQcKB2kO6EHbaXzHmUE5xV6cAOEyKOWoK2Omhv9yq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