mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-23 18:38:30 +08:00
[libcxx] Avoid spurious construction of valarray elements
Summary: Currently libc++ implements some operations on valarray by using the resize method. This method has a parameter with a default value. Because of this, valarray may spuriously construct and destruct objects of valarray's element type. This patch fixes this issue and adds corresponding test cases. Reviewers: EricWF, mclow.lists Reviewed By: mclow.lists Subscribers: rogfer01, cfe-commits Differential Revision: https://reviews.llvm.org/D41992 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@324596 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -16,6 +16,15 @@
|
||||
#include <valarray>
|
||||
#include <cassert>
|
||||
|
||||
struct S {
|
||||
S() : x(1) {}
|
||||
~S() { ++cnt_dtor; }
|
||||
int x;
|
||||
static size_t cnt_dtor;
|
||||
};
|
||||
|
||||
size_t S::cnt_dtor = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
@@ -36,4 +45,11 @@ int main()
|
||||
for (int i = 0; i < 100; ++i)
|
||||
assert(v[i].size() == 0);
|
||||
}
|
||||
{
|
||||
std::valarray<S> v(100);
|
||||
assert(v.size() == 100);
|
||||
for (int i = 0; i < 100; ++i)
|
||||
assert(v[i].x == 1);
|
||||
}
|
||||
assert(S::cnt_dtor == 100);
|
||||
}
|
||||
|
Reference in New Issue
Block a user