Issue 83838
Summary Clang initializer_list inside a global struct variable generates undef elements
Labels clang
Assignees
Reporter Qwinci
    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
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to