<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/83838>83838</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang initializer_list inside a global struct variable generates undef elements
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Qwinci
</td>
</tr>
</table>
<pre>
Clang generates an undef in place of the `"arm,gic-v3"` string_view in this case
```cpp
#include <cstddef>
#include <initializer_list>
class string_view {
public:
constexpr string_view(const char* s) :_size {} {
while (*s++) ++_size;
}
private:
size_t _size;
};
struct MyStruct {
std::initializer_list<const string_view> list {};
};
static MyStruct FOO {
.list {"arm,gic-v3"}
};
```
I am not sure if having an initializer_list inside a global struct variable like this is allowed by the standard as a global initializer_list variable certainly is allowed. At least gcc works fine with this case and clang works too if you either make the global variable constexpr, string_view constructor consteval or modify it like this
```cpp
class string_view {
public:
constexpr basic_string_view(const T* s) : _ptr {s}, _size {const_strlen(s)} {}
private:
static constexpr size_t const_strlen(const char* s) {
size_t len = 0;
while (*s++) ++len;
return len;
}
size_t _size;
};
```
Here is a godbolt link https://godbolt.org/z/dvo74zPab
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVdGO6jYQ_RrzMlqUtRMCD3lg4aL2obqt2nfkOJNkusZGtgNlv75yEgiw26veVZQNmZkzcybnyNJ7agxiwbI3lm1nsgutdcUfZzKKZqWtLsVGS9NAgwadDOhBGuhMhTWQgaOWCsHWEFoEtkgY59IdGN80pF5OgnHOFgn44Mg0-xPhORaFljwo6ZElW5as-7r-Usfj8IpxQUbprkJgYqN8qCqsmfj2VZQMBZKaPtDtNfkwpfV3paX3DxOw_G0IHbtSk2JizAQAUNb4gP8c3X0F48v-PahWOsbX4BlfARPrvacP7PHy7QQL49-5JY3A-JLxtWf8rb9WMDz1pUxcS1i-HWdydJIBH4aKqfsAjyWx4vbc331wnQrw2-XP4WEayIcqAor1511tBmb3bMU3iLGR1w8bykBqarj7_v1xC_MbzmdZXAk_wF6FMPz8FeQBjA3gO4dANbTyRKaJAnwmAmQ8VQgSGm1LqWFcxkk6kqVG0PSOg_DIg9TanrGC8tLr1gdpKukqkH4C-NThBqXQBUlGX-6g5rAOoFH6AI1ScLbu3UNNBuFMoZ0UD9JUoHpDDTnB2sjsYjtACi06OMh-UrwOMvW9apPxzYOg-0Cka92YdJIarIODrai-AIWJ_tOib477_zZhyWpySSk9qf1XXvnr3iiwPwYXEX383HwDN-f0yRFAo2F8GQuuZvovS7BkNSrvzq2DRZ7QvnJtfpPwKgINdRoNMLGF5E7hMfxDC8cej-kOQ-cMPAduUv8JRz864ReMBujVaavS6vhBzTu0IRx93AvfMb4bQ3PrGsZ3H4zvqpPN04_fZTmrClGtxErOsHjNk1WWLUSSztpisZK55BnyV57xFHORiipb5Arz1zqvs3xGBU94mogkfeVplqTzeqmWy3qR8qrM-GsuWJrgQZKea306xN4z8r7DYimWYjnTskTt-8OF81730fvZduaKmP9Sdo1naRIN5ieEQEHjeO78tNOng2o4pVDjAU3ws87p4mljFNqunCt7YHwXu4__Xo7O_o0qML7ryXjGdz2ffwMAAP__cpw8Sg">