<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/141103>141103</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
std::construct_at() seems to bypass [[clang::require_explicit_initialization]]
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
higher-performance
</td>
</tr>
</table>
<pre>
```
#include <memory>
#include <utility>
struct S {
unsigned char v [[clang::require_explicit_initialization]];
};
template <class T, class... U>
constexpr T* my_construct_at(T* ptr, U&&... args) {
return ::new (static_cast<void*>(ptr)) T(std::forward<U>(args)...);
}
int main() {
unsigned char buf[sizeof(S)];
std::construct_at(reinterpret_cast<S*>(buf));
// my_construct_at(reinterpret_cast<S*>(buf));
}
```
This code produces:
```
<source>:10:42: error: field in 'S' requires explicit initialization but is not explicitly initialized [-Werror,-Wuninitialized-explicit-init]
10 | return ::new (static_cast<void*>(ptr)) T(std::forward<U>(args)...);
| ^
<source>:16:5: note: in instantiation of function template specialization 'my_construct_at<S>' requested here
16 | my_construct_at(reinterpret_cast<S*>(buf));
| ^
<source>:5:19: note: 'v' declared here
5 | unsigned char v [[clang::require_explicit_initialization]];
| ^
```
However, it runs fine if `my_construct_at(...)` is commented out.
It appears the compiler is treating `std::construct_at` specially somehow -- either disabling warnings on it, or rewriting it internally in some way. This should not be possible. It breaks the initialization guarantee of `[[clang::require_explicit_initialization]]`.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8VVuP2zYT_TX0y8CCRNmS_aAHrZPFl-fNIo8LShpZ85UiVXJkx_n1BelLvJeiaFrUMCCCHJ45c-ZC5T3tDWIl1g9i_WmhZh6sqwbaD-iWE7reulGZFheN7U6VKNLLP62FzMm0eu4QRL4bcbTuJPLP705mJk18PUprz25uGZ5AlA8irQEAZhNZdNAOysEBIpmHViuzF3kt8trh7zM5fMHvk6aW-IUMMSlN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