SFINAE __bit_iterator such that it will only get instantiated with a container that has the nested type __storage_type. This prevents accidental instantiation such as in http://llvm.org/bugs/show_bug.cgi?id=12755. This fixes http://llvm.org/bugs/show_bug.cgi?id=12755.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@156308 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant 2012-05-07 16:50:38 +00:00
parent d2da6d2322
commit f867f6326b
3 changed files with 7 additions and 6 deletions

View File

@ -22,7 +22,7 @@
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Cp, bool _IsConst> class __bit_iterator; template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0> class __bit_iterator;
template <class _Cp> class __bit_const_reference; template <class _Cp> class __bit_const_reference;
template <class _Tp> template <class _Tp>
@ -1057,7 +1057,8 @@ equal(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __b
return __equal_unaligned(__first1, __last1, __first2); return __equal_unaligned(__first1, __last1, __first2);
} }
template <class _Cp, bool _IsConst> template <class _Cp, bool _IsConst,
typename _Cp::__storage_type>
class __bit_iterator class __bit_iterator
{ {
public: public:

View File

@ -148,9 +148,9 @@ class __bitset
public: public:
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef size_t size_type; typedef size_t size_type;
typedef size_type __storage_type;
protected: protected:
typedef __bitset __self; typedef __bitset __self;
typedef size_type __storage_type;
typedef __storage_type* __storage_pointer; typedef __storage_type* __storage_pointer;
typedef const __storage_type* __const_storage_pointer; typedef const __storage_type* __const_storage_pointer;
static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
@ -406,9 +406,9 @@ class __bitset<1, _Size>
public: public:
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef size_t size_type; typedef size_t size_type;
typedef size_type __storage_type;
protected: protected:
typedef __bitset __self; typedef __bitset __self;
typedef size_type __storage_type;
typedef __storage_type* __storage_pointer; typedef __storage_type* __storage_pointer;
typedef const __storage_type* __const_storage_pointer; typedef const __storage_type* __const_storage_pointer;
static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
@ -549,9 +549,9 @@ class __bitset<0, 0>
public: public:
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef size_t size_type; typedef size_t size_type;
typedef size_type __storage_type;
protected: protected:
typedef __bitset __self; typedef __bitset __self;
typedef size_type __storage_type;
typedef __storage_type* __storage_pointer; typedef __storage_type* __storage_pointer;
typedef const __storage_type* __const_storage_pointer; typedef const __storage_type* __const_storage_pointer;
static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);

View File

@ -1970,6 +1970,7 @@ public:
typedef allocator_traits<allocator_type> __alloc_traits; typedef allocator_traits<allocator_type> __alloc_traits;
typedef typename __alloc_traits::size_type size_type; typedef typename __alloc_traits::size_type size_type;
typedef typename __alloc_traits::difference_type difference_type; typedef typename __alloc_traits::difference_type difference_type;
typedef size_type __storage_type;
typedef __bit_iterator<vector, false> pointer; typedef __bit_iterator<vector, false> pointer;
typedef __bit_iterator<vector, true> const_pointer; typedef __bit_iterator<vector, true> const_pointer;
#ifdef _LIBCPP_DEBUG #ifdef _LIBCPP_DEBUG
@ -1991,7 +1992,6 @@ public:
typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
private: private:
typedef size_type __storage_type;
typedef typename __alloc_traits::template typedef typename __alloc_traits::template
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
rebind_alloc<__storage_type> rebind_alloc<__storage_type>