<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - std::array<T, 0> is invalid if T has a non-trivial destructor"
href="https://bugs.llvm.org/show_bug.cgi?id=46137">46137</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>std::array<T, 0> is invalid if T has a non-trivial destructor
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>leonardchan@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
</td>
</tr></table>
<p>
<div>
<pre>Currently, it seems we cannot create an empty std::array of type S if S has a
non-trivial destructor:
```
#include <array>
struct S {
~S(){}
};
template <typename T>
S DoSomething(const T&) {
return S();
}
template <typename... As>
void other_func(As&&... args) {
(void)(std::array<S, sizeof...(As)>{DoSomething(args)...});
}
void func() {
other_func(); // error
other_func(0); // ok
std::array<S, 0> x; // error
std::array<S, 1> y; // ok
(void)x;
(void)y;
}
```
This compiled with ToT clang (`clang++ -std=c++17 -c test.cc`) returns
```
test.cc:20:20: error: call to implicitly-deleted default constructor of
'std::array<S, 0>'
std::array<S, 0> x; // bad
^
/usr/local/google/home/leonardchan/llvm-monorepo/llvm-build-1-master-fuchsia-toolchain/install/bin/../include/c++/v1/array:252:7:
note: default constructor of 'array<S, 0>' is implicitly deleted because field
'__w' has a deleted destructor
} __w;
^
/usr/local/google/home/leonardchan/llvm-monorepo/llvm-build-1-master-fuchsia-toolchain/install/bin/../include/c++/v1/array:248:9:
note: explicitly defaulted function was implicitly deleted here
~__wrapper() = default;
^
/usr/local/google/home/leonardchan/llvm-monorepo/llvm-build-1-master-fuchsia-toolchain/install/bin/../include/c++/v1/array:251:13:
note: destructor of '__wrapper' is implicitly deleted because variant field
'__t' has a non-trivial destructor
_Tp __t;
^
test.cc:20:20: error: attempt to use a deleted function
std::array<S, 0> x; // bad
^
... and a couple more
```
`std::array<S, 0>` should be valid regardless of constraints specified about T.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>