[llvm-bugs] [Bug 46137] New: std::array<T, 0> is invalid if T has a non-trivial destructor
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri May 29 16:09:43 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=46137
Bug ID: 46137
Summary: std::array<T, 0> is invalid if T has a non-trivial
destructor
Product: libc++
Version: unspecified
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: leonardchan at google.com
CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200529/3620321a/attachment.html>
More information about the llvm-bugs
mailing list