<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/126299>126299</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[[clang::require_explicit_initialization]] inconsistent with constructability traits (problem under -Werror)
</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>
Someone pointed out that `[[clang::require_explicit_initialization]]` doesn't interact well with the constructability traits:
```
// -Werror=uninitialized-explicit-init
#include <type_traits>
template<class T, bool = std::is_default_constructible<T>::value>
struct DefaultValue {
static void Get() { }
};
template<class T>
struct DefaultValue<T, true> {
static T Get() {
return T();
}
};
struct S {
int x [[clang::require_explicit_initialization]];
};
int main() {
DefaultValue<S>::Get();
}
```
The problem is exacerbated under `-Werror` (which is precisely the desired flag here) because there is no way for code to know the truth about constructability.
On the other hand, when the attribute is a warning, then constructability technically isn't affected, and the warning can be suppressed. But I'm not sure we want `-W` to affect the trait behaviors, either.
I don't know what to do here, but I wanted to raise this issue in case we want to make any changes prior to the release of LLVM 20.
@AaronBallman
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVM9u4zgPfxrlQiRw5SSODzkkzdcPA8xiDy1mjwUtMTF3FMkr0U2zT7-Q7bQzHfSwGxgIIJG_PxRJTIlPnmirVnu1OsywlzbEbcunluK8o3gM8Yze0KwJ9rp9DGcKnqAL7IUshF5AWhRQ62JA2BuH_qTKnSp3kf7qOdIzvXaODcszexZGx3-jcPBqdcjfugAbKHmlK4GMGtEIXMg5uLC0IC2BCT5J7I1gw47lChKRJWWaYvjWxfQVO6UflH6A-R8UY4iqPPT-jZfs_CZmng-nbF2yN663BKq8l2tHzzf8_40RQufOoZAq743DlOBJ6XtoQnCgygMksaNjTs-Wjtg7eX6TzI3LeU8ZbAh6QdfTCD1GwGHM-ZYvQFV7VewAAJKgsIG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