Implement LWG#2596: 'vector::data() should use addressof'

llvm-svn: 274241
This commit is contained in:
Marshall Clow 2016-06-30 15:50:55 +00:00
parent c3201ee5f1
commit 81fce9729c
3 changed files with 42 additions and 4 deletions

View File

@ -17,6 +17,15 @@
#include "min_allocator.h"
#include "asan_testing.h"
struct Nasty {
Nasty() : i_(0) {}
Nasty(int i) : i_(i) {}
~Nasty() {}
Nasty * operator&() const { assert(false); return nullptr; }
int i_;
};
int main()
{
{
@ -26,7 +35,12 @@ int main()
}
{
std::vector<int> v(100);
assert(v.data() == &v.front());
assert(v.data() == std::addressof(v.front()));
assert(is_contiguous_container_asan_correct(v));
}
{
std::vector<Nasty> v(100);
assert(v.data() == std::addressof(v.front()));
assert(is_contiguous_container_asan_correct(v));
}
#if TEST_STD_VER >= 11
@ -37,7 +51,12 @@ int main()
}
{
std::vector<int, min_allocator<int>> v(100);
assert(v.data() == &v.front());
assert(v.data() == std::addressof(v.front()));
assert(is_contiguous_container_asan_correct(v));
}
{
std::vector<Nasty, min_allocator<Nasty>> v(100);
assert(v.data() == std::addressof(v.front()));
assert(is_contiguous_container_asan_correct(v));
}
#endif

View File

@ -17,6 +17,15 @@
#include "min_allocator.h"
#include "asan_testing.h"
struct Nasty {
Nasty() : i_(0) {}
Nasty(int i) : i_(i) {}
~Nasty() {}
Nasty * operator&() const { assert(false); return nullptr; }
int i_;
};
int main()
{
{
@ -26,7 +35,12 @@ int main()
}
{
const std::vector<int> v(100);
assert(v.data() == &v.front());
assert(v.data() == std::addressof(v.front()));
assert(is_contiguous_container_asan_correct(v));
}
{
std::vector<Nasty> v(100);
assert(v.data() == std::addressof(v.front()));
assert(is_contiguous_container_asan_correct(v));
}
#if TEST_STD_VER >= 11
@ -40,5 +54,10 @@ int main()
assert(v.data() == &v.front());
assert(is_contiguous_container_asan_correct(v));
}
{
std::vector<Nasty, min_allocator<Nasty>> v(100);
assert(v.data() == std::addressof(v.front()));
assert(is_contiguous_container_asan_correct(v));
}
#endif
}

View File

@ -279,7 +279,7 @@
<tr><td><a href="http://wg21.link/LWG2551">2551</a></td><td>[fund.ts.v2] "Exception safety" cleanup in library fundamentals required</td><td>Oulu</td><td></td></tr>
<tr><td><a href="http://wg21.link/LWG2555">2555</a></td><td>[fund.ts.v2] No handling for over-aligned types in optional</td><td>Oulu</td><td></td></tr>
<tr><td><a href="http://wg21.link/LWG2573">2573</a></td><td>[fund.ts.v2] std::hash&lt;std::experimental::shared_ptr&gt; does not work for arrays</td><td>Oulu</td><td></td></tr>
<tr><td><a href="http://wg21.link/LWG2596">2596</a></td><td>vector::data() should use addressof</td><td>Oulu</td><td></td></tr>
<tr><td><a href="http://wg21.link/LWG2596">2596</a></td><td>vector::data() should use addressof</td><td>Oulu</td><td>Complete</td></tr>
<tr><td><a href="http://wg21.link/LWG2667">2667</a></td><td>path::root_directory() description is confusing</td><td>Oulu</td><td></td></tr>
<tr><td><a href="http://wg21.link/LWG2669">2669</a></td><td>recursive_directory_iterator effects refers to non-existent functions</td><td>Oulu</td><td></td></tr>
<tr><td><a href="http://wg21.link/LWG2670">2670</a></td><td>system_complete refers to undefined variable 'base'</td><td>Oulu</td><td></td></tr>