<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/55938>55938</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MSYS2] Ordered dynamic initialization is not sequenced
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
silverqx
</td>
</tr>
</table>
<pre>
Following simple code example crashes on MSYS2 UCRT64 clang++. All other compilers don't have problem with this, gcc/clang on linux, msvc or clang-cl msvc and also MSYS2 UCRT64 g++.
It crashes because `ConstAppInline::LEFT` is uninitialized during the `Model::m_fillable` initialization.
I think that this is happening, here should apply [`Ordered dynamic initialization` ](https://en.cppreference.com/w/cpp/language/initialization#Dynamic_initialization), so the initialization should be sequenced:
> within a single translation unit, initialization of these variables is always [sequenced](https://en.cppreference.com/w/cpp/language/eval_order) in exact order their definitions appear in the source code.
The consequence is that you can not initialize inline static data member with inline const global variable with external linkage. ☝️
<details>
<summary>Click to expand!</summary>
```cpp
#include <iostream>
#include <string>
#include <vector>
//#include <QDebug>
//#include <QStringLiteral>
namespace ConstAppInline
{
// Common chars
// inline const QChar DOT = QChar('.');
// Common strings
inline const std::string LEFT = "left";
// inline const QString LEFT = "left";
} // namespace ConstAppInline
class Model
{
inline static std::vector<std::string> m_fillable {ConstAppInline::LEFT};
// inline static QStringList m_fillable {ConstAppInline::LEFT};
public:
inline void run() const
{
std::cout << m_fillable.size() << "\n";
for (const auto &s : m_fillable)
std::cout << s << "\n";
// qDebug() << m_fillable.size();
// qDebug() << m_fillable;
}
};
int main(int /*unused*/, char */*unused*/[])
{
Model m;
m.run();
return 0;
}
```
</details>
The example contains two types, one types from stl library and other for Qt types, in both versions the `ConstAppInline::LEFT` is **uninitialized**.
Qt version crashes and the output with stl types is like following:
```
1
```
Of course, it should look like this with stl types:
```
1
left
```
And like this with Qt types:
```
1
QList("left")
```
This is the long-running bug that I'm experiencing with during the development of one of my libraries and hoped that it will be fixed, but it wasn't. The problem exists as long as I remember, from `Clang 10/11`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylV01z4jgQ_TXmohrKmEDgwIFAqErVTE1lkz3sKSXbArSRJY8kk7C_fl9LYDBDJls7lDFYH92vX3-onZtyP1sZpcyb1BvmZFUrwQpTCibeeXyw3G2FY0azb09_PWXsz8Ufz-MbViiuN0l2h6vP5kox47fCYm9VSyWsY6XRSXbr2ZbvBKutyZWo2Jv0W-a30iXZgm2KIslWQRCJV1I37zReuV3BjI0qvhQqDnBdMq6c6cI4QkjSZZLO4_3Bt6hzUfDGCZaM04XRzs_r-kFDkUiGc1xf71fPmGLSsUZLLb3kSv4jSlY2lgiBSbT1GwhRcUf1spZKcRgT9h23cC-N7oIgM_Ur7twHi0nJlte1gKINmQm6BHNb0ygYVtdqz5LRHaR-tyVmgGGveSWLCyWkNhktk2yy9b52hCpb4RK6X9S1FWvs1YXowxEYfSOC6xp34rLhG4G_FwKz4TJqermcmBJMME40dOeOuHNYIH40pLEkKGcEJMP74G6pGUdk6Q2CyVuunYoSQLgn-ReCzZrUwWU7biXxHIjj6o3vHRF0Uvd7JIgdVy-GqIadAEEBX3gWRgiBtKwU6wAOgUMOEtzSOiLDmcYWMVE6Tn_e0qA-YiTkwf9707CCa6aNP9lLnFIoMudhesFK7jmrRJUDQMiTwzQJ9GyjTM5Vy0pcId69sBrDWPgKu_osuc-S6SSZLpP7VXI3SSarrk8WpfBcKlB23w65pqq43WNooWSBkDUQXCPfkmyAaZB1WnEujVIjXsRunMiGUheqQQHBTmmct4JXp32daUxSKlyf3InCG3uhMXq5u_BxKfLmXMqVJU9B01cJtri6kInQF67m8NZFhYhrbu86JuMTNWB1VSFeiy237lw1Lel47nGBJWz5_RlQlvEJgYva2MeXkmz4iYrIkztNd8Q7X8bSFJcxqmlBU5JlSqyRY9lJwwcIn_7D1gMdyyO4T3g7u6OOO8diEe2SeobkkAStNUf_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