Add static_assert to set/multiset/map/multimap/forward_list/deque that the allocator's value_type match the container's value_type. vector/unordered/list/string already do this. Add tests for all the containers to verify this.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@254119 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow 2015-11-26 01:24:04 +00:00
parent 5a579cfea4
commit 14ba0ad689
17 changed files with 252 additions and 0 deletions

View File

@ -1196,6 +1196,9 @@ public:
typedef _Tp value_type;
typedef _Allocator allocator_type;
static_assert((is_same<typename allocator_type::value_type, value_type>::value),
"Allocator::value_type must be same type as value_type");
typedef __deque_base<value_type, allocator_type> __base;
typedef typename __base::__alloc_traits __alloc_traits;

View File

@ -537,6 +537,9 @@ public:
typedef _Tp value_type;
typedef _Alloc allocator_type;
static_assert((is_same<typename allocator_type::value_type, value_type>::value),
"Allocator::value_type must be same type as value_type");
typedef value_type& reference;
typedef const value_type& const_reference;
typedef typename allocator_traits<allocator_type>::pointer pointer;

View File

@ -840,6 +840,9 @@ public:
typedef value_type& reference;
typedef const value_type& const_reference;
static_assert((is_same<typename allocator_type::value_type, value_type>::value),
"Allocator::value_type must be same type as value_type");
class _LIBCPP_TYPE_VIS_ONLY value_compare
: public binary_function<value_type, value_type, bool>
{
@ -1696,6 +1699,9 @@ public:
typedef value_type& reference;
typedef const value_type& const_reference;
static_assert((is_same<typename allocator_type::value_type, value_type>::value),
"Allocator::value_type must be same type as value_type");
class _LIBCPP_TYPE_VIS_ONLY value_compare
: public binary_function<value_type, value_type, bool>
{

View File

@ -409,6 +409,9 @@ public:
typedef value_type& reference;
typedef const value_type& const_reference;
static_assert((is_same<typename allocator_type::value_type, value_type>::value),
"Allocator::value_type must be same type as value_type");
private:
typedef __tree<value_type, value_compare, allocator_type> __base;
typedef allocator_traits<allocator_type> __alloc_traits;
@ -819,6 +822,9 @@ public:
typedef value_type& reference;
typedef const value_type& const_reference;
static_assert((is_same<typename allocator_type::value_type, value_type>::value),
"Allocator::value_type must be same type as value_type");
private:
typedef __tree<value_type, value_compare, allocator_type> __base;
typedef allocator_traits<allocator_type> __alloc_traits;

View File

@ -0,0 +1,18 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <map>
// The container's value type must be the same as the allocator's value type
#include <map>
int main()
{
std::map<int, int, std::less<int>, std::allocator<long> > m;
}

View File

@ -0,0 +1,18 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <map>
// The container's value type must be the same as the allocator's value type
#include <map>
int main()
{
std::multimap<int, int, std::less<int>, std::allocator<long> > m;
}

View File

@ -0,0 +1,18 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <set>
// The container's value type must be the same as the allocator's value type
#include <set>
int main()
{
std::multiset<int, std::less<int>, std::allocator<long> > ms;
}

View File

@ -0,0 +1,18 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <set>
// The container's value type must be the same as the allocator's value type
#include <set>
int main()
{
std::set<int, std::less<int>, std::allocator<long> > s;
}

View File

@ -0,0 +1,18 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <deque>
// The container's value type must be the same as the allocator's value type
#include <deque>
int main()
{
std::deque<int, std::allocator<long> > d;
}

View File

@ -0,0 +1,18 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <forward_list>
// The container's value type must be the same as the allocator's value type
#include <forward_list>
int main()
{
std::forward_list<int, std::allocator<long> > fl;
}

View File

@ -0,0 +1,18 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <list>
// The container's value type must be the same as the allocator's value type
#include <list>
int main()
{
std::list<int, std::allocator<long> > l;
}

View File

@ -0,0 +1,18 @@
//===----------------------------------------------------------------------===//
//
// 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>
// The container's value type must be the same as the allocator's value type
#include <vector>
int main()
{
std::vector<int, std::allocator<long> > v;
}

View File

@ -0,0 +1,18 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <unordered_map>
// The container's value type must be the same as the allocator's value type
#include <unordered_map>
int main()
{
std::unordered_map<int, int, std::hash<int>, std::less<int>, std::allocator<long> > m;
}

View File

@ -0,0 +1,18 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <unordered_map>
// The container's value type must be the same as the allocator's value type
#include <unordered_map>
int main()
{
std::unordered_multimap<int, int, std::hash<int>, std::less<int>, std::allocator<long> > m;
}

View File

@ -0,0 +1,18 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <unordered_set>
// The container's value type must be the same as the allocator's value type
#include <unordered_set>
int main()
{
std::unordered_multiset<int, std::hash<int>, std::less<int>, std::allocator<long> > v;
}

View File

@ -0,0 +1,18 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <unordered_set>
// The container's value type must be the same as the allocator's value type
#include <unordered_set>
int main()
{
std::unordered_set<int, std::hash<int>, std::less<int>, std::allocator<long> > v;
}

View File

@ -0,0 +1,18 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <string>
// The container's value type must be the same as the allocator's value type
#include <string>
int main()
{
std::basic_string<char, std::char_traits<char>, std::allocator<int> > s;
}