diff options
| author | Eric Fiselier <eric@efcs.ca> | 2017-09-15 00:31:38 +0000 |
|---|---|---|
| committer | Eric Fiselier <eric@efcs.ca> | 2017-09-15 00:31:38 +0000 |
| commit | 9f8fef95047e37ebdbac88dfebecd282e09c47df (patch) | |
| tree | fd60a63fa0afe9c37a255773a4f10d6a607210d1 /libcxx/test/std/utilities | |
| parent | 4c33079dc3dec95767d4887eebb0995716edeac5 (diff) | |
| download | bcm5719-llvm-9f8fef95047e37ebdbac88dfebecd282e09c47df.tar.gz bcm5719-llvm-9f8fef95047e37ebdbac88dfebecd282e09c47df.zip | |
Fix accidental ADL in std::allocator_traits meta-programming.
There were a number of cases where __double_underscore functions,
for example __has_construct_test, were called without being qualified,
causing ADL to occur. This patch qualifies those calls to avoid this
problem.
Thanks to David L. Jones for point out the issue initially.
llvm-svn: 313324
Diffstat (limited to 'libcxx/test/std/utilities')
8 files changed, 84 insertions, 0 deletions
diff --git a/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp index ab8179c5ab4..292d68de978 100644 --- a/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp +++ b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp @@ -20,6 +20,8 @@ #include <cstdint> #include <cassert> +#include "incomplete_type_helper.h" + template <class T> struct A { @@ -34,6 +36,14 @@ struct A int main() { + { A<int> a; assert(std::allocator_traits<A<int> >::allocate(a, 10) == reinterpret_cast<int*>(static_cast<std::uintptr_t>(0xDEADBEEF))); + } + { + typedef IncompleteHolder* VT; + typedef A<VT> Alloc; + Alloc a; + assert(std::allocator_traits<Alloc >::allocate(a, 10) == reinterpret_cast<VT*>(static_cast<std::uintptr_t>(0xDEADBEEF))); + } } diff --git a/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp index 808284261f7..90a9154e184 100644 --- a/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp +++ b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp @@ -21,6 +21,7 @@ #include <cassert> #include "test_macros.h" +#include "incomplete_type_helper.h" template <class T> struct A @@ -52,12 +53,29 @@ struct B } }; + int main() { #if TEST_STD_VER >= 11 + { A<int> a; assert(std::allocator_traits<A<int> >::allocate(a, 10, nullptr) == reinterpret_cast<int*>(static_cast<std::uintptr_t>(0xDEADBEEF))); + } + { + typedef IncompleteHolder* VT; + typedef A<VT> Alloc; + Alloc a; + assert(std::allocator_traits<Alloc >::allocate(a, 10, nullptr) == reinterpret_cast<VT*>(static_cast<std::uintptr_t>(0xDEADBEEF))); + } #endif + { B<int> b; assert(std::allocator_traits<B<int> >::allocate(b, 11, nullptr) == reinterpret_cast<int*>(static_cast<std::uintptr_t>(0xFEADBEEF))); + } + { + typedef IncompleteHolder* VT; + typedef B<VT> Alloc; + Alloc b; + assert(std::allocator_traits<Alloc >::allocate(b, 11, nullptr) == reinterpret_cast<VT*>(static_cast<std::uintptr_t>(0xFEADBEEF))); + } } diff --git a/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp index 46075f62c6c..e4aceffdd6b 100644 --- a/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp +++ b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp @@ -23,6 +23,7 @@ #include <cassert> #include "test_macros.h" +#include "incomplete_type_helper.h" template <class T> struct A @@ -107,6 +108,13 @@ int main() std::allocator_traits<A<int> >::construct(a, (A2*)&a2, 'd', 5); assert(A2::count == 1); } + { + typedef IncompleteHolder* VT; + typedef A<VT> Alloc; + Alloc a; + std::aligned_storage<sizeof(VT)>::type store; + std::allocator_traits<Alloc>::construct(a, (VT*)&store, nullptr); + } #if TEST_STD_VER >= 11 { A0::count = 0; diff --git a/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/deallocate.pass.cpp b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/deallocate.pass.cpp index 8176d8b3767..ecb67adb58e 100644 --- a/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/deallocate.pass.cpp +++ b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/deallocate.pass.cpp @@ -20,6 +20,8 @@ #include <cstdint> #include <cassert> +#include "incomplete_type_helper.h" + int called = 0; template <class T> @@ -37,7 +39,17 @@ struct A int main() { + { A<int> a; std::allocator_traits<A<int> >::deallocate(a, reinterpret_cast<int*>(static_cast<std::uintptr_t>(0xDEADBEEF)), 10); assert(called == 1); + } + called = 0; + { + typedef IncompleteHolder* VT; + typedef A<VT> Alloc; + Alloc a; + std::allocator_traits<Alloc >::deallocate(a, reinterpret_cast<VT*>(static_cast<std::uintptr_t>(0xDEADBEEF)), 10); + assert(called == 1); + } } diff --git a/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp index 2ee64b8b4a0..1a812876bf0 100644 --- a/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp +++ b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp @@ -23,6 +23,7 @@ #include <cassert> #include "test_macros.h" +#include "incomplete_type_helper.h" template <class T> struct A @@ -65,6 +66,13 @@ int main() std::allocator_traits<A<int> >::destroy(a, (A0*)&a0); assert(A0::count == 1); } + { + typedef IncompleteHolder* VT; + typedef A<VT> Alloc; + Alloc a; + std::aligned_storage<sizeof(VT)>::type store; + std::allocator_traits<Alloc>::destroy(a, (VT*)&store); + } #if TEST_STD_VER >= 11 { A0::count = 0; diff --git a/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/incomplete_type_helper.h b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/incomplete_type_helper.h new file mode 100644 index 00000000000..7662338d73c --- /dev/null +++ b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/incomplete_type_helper.h @@ -0,0 +1,14 @@ +#ifndef TEST_INCOMPLETE_TYPE_HELPER_H +#define TEST_INCOMPLETE_TYPE_HELPER_H + +#include "min_allocator.h" + +namespace NS { + struct Incomplete; +} + +template <class T> struct Holder { T value; }; + +typedef Holder<NS::Incomplete> IncompleteHolder; + +#endif diff --git a/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp index d2c9a9826e1..12c0d02227f 100644 --- a/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp +++ b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp @@ -22,6 +22,7 @@ #include <cassert> #include "test_macros.h" +#include "incomplete_type_helper.h" template <class T> struct A @@ -51,6 +52,12 @@ int main() const B<int> b = {}; assert(std::allocator_traits<B<int> >::max_size(b) == 100); } + { + typedef IncompleteHolder* VT; + typedef B<VT> Alloc; + Alloc a; + assert(std::allocator_traits<Alloc >::max_size(a) == 100); + } #if TEST_STD_VER >= 11 { A<int> a; diff --git a/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp index 2e970303789..8355db18276 100644 --- a/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp +++ b/libcxx/test/std/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp @@ -23,6 +23,7 @@ #include <cassert> #include "test_macros.h" +#include "incomplete_type_helper.h" template <class T> struct A @@ -57,6 +58,12 @@ int main() const A<int> a(0); assert(std::allocator_traits<A<int> >::select_on_container_copy_construction(a).id == 0); } + { + typedef IncompleteHolder* VT; + typedef A<VT> Alloc; + Alloc a; + assert(std::allocator_traits<Alloc>::select_on_container_copy_construction(a).id == 0); + } #if TEST_STD_VER >= 11 { B<int> b; |

