While testing Erik's code coverage scripts, I found a hole in the test suite - vector::assign where a reallocation was not required had no tests. Add some
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@233557 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -17,29 +17,36 @@
|
||||
#include "min_allocator.h"
|
||||
#include "asan_testing.h"
|
||||
|
||||
template <typename Vec>
|
||||
void test ( Vec &v )
|
||||
{
|
||||
v.assign({3, 4, 5, 6});
|
||||
assert(v.size() == 4);
|
||||
assert(is_contiguous_container_asan_correct(v));
|
||||
assert(v[0] == 3);
|
||||
assert(v[1] == 4);
|
||||
assert(v[2] == 5);
|
||||
assert(v[3] == 6);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
|
||||
{
|
||||
std::vector<int> d;
|
||||
d.assign({3, 4, 5, 6});
|
||||
assert(d.size() == 4);
|
||||
assert(is_contiguous_container_asan_correct(d));
|
||||
assert(d[0] == 3);
|
||||
assert(d[1] == 4);
|
||||
assert(d[2] == 5);
|
||||
assert(d[3] == 6);
|
||||
typedef std::vector<int> V;
|
||||
V d1;
|
||||
V d2(10); // no reallocation during assign.
|
||||
test(d1);
|
||||
test(d2);
|
||||
}
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
{
|
||||
std::vector<int, min_allocator<int>> d;
|
||||
d.assign({3, 4, 5, 6});
|
||||
assert(d.size() == 4);
|
||||
assert(is_contiguous_container_asan_correct(d));
|
||||
assert(d[0] == 3);
|
||||
assert(d[1] == 4);
|
||||
assert(d[2] == 5);
|
||||
assert(d[3] == 6);
|
||||
typedef std::vector<int, min_allocator<int>> V;
|
||||
V d1;
|
||||
V d2(10); // no reallocation during assign.
|
||||
test(d1);
|
||||
test(d2);
|
||||
}
|
||||
#endif
|
||||
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <vector>
|
||||
|
||||
// void assign(size_type n, const_reference v);
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
#include "min_allocator.h"
|
||||
#include "asan_testing.h"
|
||||
|
||||
bool is6(int x) { return x == 6; }
|
||||
|
||||
template <typename Vec>
|
||||
void test ( Vec &v )
|
||||
{
|
||||
v.assign(5, 6);
|
||||
assert(v.size() == 5);
|
||||
assert(is_contiguous_container_asan_correct(v));
|
||||
assert(std::all_of(v.begin(), v.end(), is6));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::vector<int> V;
|
||||
V d1;
|
||||
V d2(10); // no reallocation during assign.
|
||||
test(d1);
|
||||
test(d2);
|
||||
}
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
{
|
||||
typedef std::vector<int, min_allocator<int>> V;
|
||||
V d1;
|
||||
V d2(10); // no reallocation during assign.
|
||||
test(d1);
|
||||
test(d2);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user