[cfe-dev] [PATCH] Libc++ Windows fixes
Ruben Van Boxem
vanboxem.ruben at gmail.com
Sat Oct 22 11:05:57 PDT 2011
2011/10/19 Ruben Van Boxem <vanboxem.ruben at gmail.com>
> 2011/10/17 Howard Hinnant <hhinnant at apple.com>
>
>> Committed revision 142235.
>>
>> I modified the alignas support a little bit. If I messed it up, let me
>> know.
>>
>
> It looks okay, and compiles fine. Thanks for the continued commit support!
>
> Hi,
>
> Attached is a new patch for libc++ and msvc interoperability.
>
> I added a new MSVC only support header for <limits>, and implemented it as
> platform-specifically as I could/should :).
> I renamed a "__value" variable to "__value_"; "__value" is a CLR (MSVC's
> Managed C++) keyword, and it produces an error in non-CLR mode.
> The notable changes are at the bottom of the patch file.
>
> It gets me as far as this undecipherable error (which is in a
> _LIBCPP_HAS_NO_VARIADICS section, this will not change in the near future;
> MSVC 11.0 will not have variadic templates... grrrr):
>
> M:\Development\Source\libc++\include\type_traits(1192) : error C2516:
> 'std::common_type<_Tp>::type' : is not a legal base class
> with
> [
> _Tp=
> ]
> M:\Development\Source\libc++\include\type_traits(1122) : see
> declaration of 'std::common_type<_Tp>::type'
> with
> [
> _Tp=
> ]
> M:\Development\Source\libc++\include\type_traits(1192) : see
> reference to class template instantiation
> 'std::__is_assignable_imp<_Tp,_Arg,__formal>' being compiled
> M:\Development\Source\libc++\include\type_traits(1244) : error C2516:
> 'std::common_type<_Tp>::type' : is not a legal base class
> with
> [
> _Tp=
> ]
> M:\Development\Source\libc++\include\type_traits(1122) : see
> declaration of 'std::common_type<_Tp>::type'
> with
> [
> _Tp=
> ]
> M:\Development\Source\libc++\include\type_traits(1244) : see
> reference to class template instantiation
> 'std::__destructible_imp<_Tp,__formal>' being compiled
> M:\Development\Source\libc++\include\type_traits(2013) : error C2516:
> 'std::common_type<_Tp>::type' : is not a legal base class
> with
> [
> _Tp=
> ]
> M:\Development\Source\libc++\include\type_traits(1122) : see
> declaration of 'std::common_type<_Tp>::type'
> with
> [
> _Tp=
> ]
> M:\Development\Source\libc++\include\type_traits(2013) : see
> reference to class template instantiation
> 'std::__is_constructible0_imp<__formal,_Tp>' being compiled
> M:\Development\Source\libc++\include\type_traits(2021) : error C2516:
> 'std::common_type<_Tp>::type' : is not a legal base class
> with
> [
> _Tp=
> ]
> M:\Development\Source\libc++\include\type_traits(1122) : see
> declaration of 'std::common_type<_Tp>::type'
> with
> [
> _Tp=
> ]
> M:\Development\Source\libc++\include\type_traits(2021) : see
> reference to class template instantiation
> 'std::__is_constructible1_imp<__formal,_Tp,_A0>' being compiled
> M:\Development\Source\libc++\include\type_traits(2029) : error C2516:
> 'std::common_type<_Tp>::type' : is not a legal base class
> with
> [
> _Tp=
> ]
> M:\Development\Source\libc++\include\type_traits(1122) : see
> declaration of 'std::common_type<_Tp>::type'
> with
> [
> _Tp=
> ]
> M:\Development\Source\libc++\include\type_traits(2029) : see
> reference to class template instantiation
> 'std::__is_constructible2_imp<__formal,_Tp,_A0,_A1>' being compiled
> M:\Development\Source\libc++\include\utility(264) : error C4519: default
> template arguments are only allowed on a class template
> M:\Development\Source\libc++\include\utility(352) : see reference
> to class template instantiation 'std::pair<_T1,_T2>' being compiled
>
> There's two different errors here: C2516 and C4519. I hope these aren't
> insurmountable unimplemented template features. I'm sure you could shed more
> light on what feature or implementation detail is being relied on here. The
> second error does seem to be caused by the first.
>
Attached is a patch to further improve the almost hopeless situation :)
Also attached is a reduced (preprocessed) testcase (algorithm.cpp) producing
exactly one of the template errors. The empty template parameter types in
the error messages give the impression of a compiler bug, but I'm not quite
sure yet. I tried running (MinGW-based) Clang on the preprocessed example,
and if one ignores the missing builtin type related errors, one sees these
decltype related errors:
[... other typedef related errors with nullptr, unsigned __int64, size_t
etc...]
algorithm.cpp:140:22: error: expected parameter declarator
typedef decltype(true ? __t() : __u()) type;
^
algorithm.cpp:140:22: error: expected ')'
algorithm.cpp:140:21: note: to match this '('
typedef decltype(true ? __t() : __u()) type;
^
algorithm.cpp:140:13: error: C++ requires a type specifier for all
declarations
typedef decltype(true ? __t() : __u()) type;
~~~~~~~ ^
algorithm.cpp:140:43: error: expected ';' at end of declaration list
typedef decltype(true ? __t() : __u()) type;
^
;
algorithm.cpp:144:1: error: C++ requires a type specifier for all
declarations
decltype((std::declval<_Tp>() = std::declval<_Arg>(), true_type()))
^~~~~~~~
algorithm.cpp:144:1: error: variable 'decltype' declared as a template
decltype((std::declval<_Tp>() = std::declval<_Arg>(), true_type()))
^
algorithm.cpp:144:16: error: no member named 'declval' in namespace 'std'
decltype((std::declval<_Tp>() = std::declval<_Arg>(), true_type()))
~~~~~^
algorithm.cpp:144:24: error: '_Tp' does not refer to a value
decltype((std::declval<_Tp>() = std::declval<_Arg>(), true_type()))
^
algorithm.cpp:143:17: note: declared here
template <class _Tp, class _Arg>
^
algorithm.cpp:144:29: error: expected expression
decltype((std::declval<_Tp>() = std::declval<_Arg>(), true_type()))
^
algorithm.cpp:144:38: error: no member named 'declval' in namespace 'std'
decltype((std::declval<_Tp>() = std::declval<_Arg>(), true_type()))
~~~~~^
For once, these errors aren't really helpful :(, but they are radically
different from the MSVC errors (see above, in my quoted email). I'm building
a MSVC based Clang now, to see if it works better for libc++ (if at all).
Thanks for any insights, comments or commits!
Ruben
>
> Comments and commits welcome!
>
> Ruben
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20111022/c6eae9a0/attachment.html>
-------------- next part --------------
Index: include/cstdio
===================================================================
--- include/cstdio (revision 142723)
+++ include/cstdio (working copy)
@@ -126,13 +126,15 @@
using ::snprintf;
using ::sprintf;
using ::sscanf;
+#ifndef _MSC_VER
using ::vfprintf;
using ::vfscanf;
+using ::vscanf;
+using ::vsscanf;
+#endif // _MSC_VER
using ::vprintf;
-using ::vscanf;
using ::vsnprintf;
using ::vsprintf;
-using ::vsscanf;
using ::fgetc;
using ::fgets;
using ::fputc;
Index: include/numeric
===================================================================
--- include/numeric (revision 142723)
+++ include/numeric (working copy)
@@ -186,10 +186,10 @@
template <class _ForwardIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
void
-iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
+iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value_)
{
- for (; __first != __last; ++__first, ++__value)
- *__first = __value;
+ for (; __first != __last; ++__first, ++__value_)
+ *__first = __value_;
}
_LIBCPP_END_NAMESPACE_STD
Index: include/cwchar
===================================================================
--- include/cwchar (revision 142723)
+++ include/cwchar (working copy)
@@ -124,13 +124,15 @@
using ::fwprintf;
using ::fwscanf;
using ::swprintf;
+using ::vfwprintf;
+using ::vswprintf;
+using ::vwprintf;
+#ifndef _MSC_VER
using ::swscanf;
-using ::vfwprintf;
using ::vfwscanf;
-using ::vswprintf;
using ::vswscanf;
-using ::vwprintf;
using ::vwscanf;
+#endif // _MSC_VER
using ::wprintf;
using ::wscanf;
using ::fgetwc;
@@ -144,8 +146,10 @@
using ::putwchar;
using ::ungetwc;
using ::wcstod;
+#ifndef _MSC_VER
using ::wcstof;
using ::wcstold;
+#endif // _MSC_VER
using ::wcstol;
using ::wcstoll;
using ::wcstoul;
Index: include/cstdlib
===================================================================
--- include/cstdlib (revision 142723)
+++ include/cstdlib (working copy)
@@ -81,6 +81,9 @@
#include <__config>
#include <stdlib.h>
+#ifdef _MSC_VER
+#include "support/win32/support.h"
+#endif // _MSC_VER
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
@@ -129,11 +132,13 @@
using ::mbstowcs;
using ::wcstombs;
+#ifndef _MSC_VER // MSVC already has the correct prototype in <stdlib.h.h> #ifdef __cplusplus
inline _LIBCPP_INLINE_VISIBILITY long abs( long __x) {return labs(__x);}
inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) {return llabs(__x);}
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div( long __x, long __y) {return ldiv(__x, __y);}
inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) {return lldiv(__x, __y);}
+#endif // _MSC_VER
_LIBCPP_END_NAMESPACE_STD
Index: include/cctype
===================================================================
--- include/cctype (revision 142723)
+++ include/cctype (working copy)
@@ -37,6 +37,9 @@
#include <__config>
#include <ctype.h>
+#if defined(_MSC_VER)
+#include "support/win32/support.h"
+#endif // _MSC_VER
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
Index: include/iterator
===================================================================
--- include/iterator (revision 142723)
+++ include/iterator (working copy)
@@ -626,11 +626,11 @@
typedef _Container container_type;
_LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(&__x) {}
- _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value)
- {container->push_back(__value); return *this;}
+ _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
+ {container->push_back(__value_); return *this;}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value)
- {container->push_back(_VSTD::move(__value)); return *this;}
+ _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
+ {container->push_back(_VSTD::move(__value_)); return *this;}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
_LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
@@ -659,11 +659,11 @@
typedef _Container container_type;
_LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(&__x) {}
- _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value)
- {container->push_front(__value); return *this;}
+ _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
+ {container->push_front(__value_); return *this;}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value)
- {container->push_front(_VSTD::move(__value)); return *this;}
+ _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
+ {container->push_front(_VSTD::move(__value_)); return *this;}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
_LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
@@ -694,11 +694,11 @@
_LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
: container(&__x), iter(__i) {}
- _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value)
- {iter = container->insert(iter, __value); ++iter; return *this;}
+ _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
+ {iter = container->insert(iter, __value_); ++iter; return *this;}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value)
- {iter = container->insert(iter, _VSTD::move(__value)); ++iter; return *this;}
+ _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
+ {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
_LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
@@ -769,9 +769,9 @@
: __out_stream_(&__s), __delim_(0) {}
_LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter)
: __out_stream_(&__s), __delim_(__delimiter) {}
- _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value)
+ _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
{
- *__out_stream_ << __value;
+ *__out_stream_ << __value_;
if (__delim_)
*__out_stream_ << __delim_;
return *this;
Index: include/__bit_reference
===================================================================
--- include/__bit_reference (revision 142723)
+++ include/__bit_reference (working copy)
@@ -218,9 +218,9 @@
template <class _C, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
__bit_iterator<_C, false>
-find(__bit_iterator<_C, false> __first, __bit_iterator<_C, false> __last, const _Tp& __value)
+find(__bit_iterator<_C, false> __first, __bit_iterator<_C, false> __last, const _Tp& __value_)
{
- if (static_cast<bool>(__value))
+ if (static_cast<bool>(__value_))
return __find_bool_true(__first, static_cast<typename _C::size_type>(__last - __first));
return __find_bool_false(__first, static_cast<typename _C::size_type>(__last - __first));
}
@@ -292,9 +292,9 @@
template <class _C, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename __bit_iterator<_C, false>::difference_type
-count(__bit_iterator<_C, false> __first, __bit_iterator<_C, false> __last, const _Tp& __value)
+count(__bit_iterator<_C, false> __first, __bit_iterator<_C, false> __last, const _Tp& __value_)
{
- if (static_cast<bool>(__value))
+ if (static_cast<bool>(__value_))
return __count_bool_true(__first, static_cast<typename _C::size_type>(__last - __first));
return __count_bool_false(__first, static_cast<typename _C::size_type>(__last - __first));
}
@@ -364,11 +364,11 @@
template <class _C>
_LIBCPP_INLINE_VISIBILITY inline
void
-fill_n(__bit_iterator<_C, false> __first, typename _C::size_type __n, bool __value)
+fill_n(__bit_iterator<_C, false> __first, typename _C::size_type __n, bool __value_)
{
if (__n > 0)
{
- if (__value)
+ if (__value_)
__fill_n_true(__first, __n);
else
__fill_n_false(__first, __n);
@@ -380,9 +380,9 @@
template <class _C>
inline _LIBCPP_INLINE_VISIBILITY
void
-fill(__bit_iterator<_C, false> __first, __bit_iterator<_C, false> __last, bool __value)
+fill(__bit_iterator<_C, false> __first, __bit_iterator<_C, false> __last, bool __value_)
{
- _VSTD::fill_n(__first, static_cast<typename _C::size_type>(__last - __first), __value);
+ _VSTD::fill_n(__first, static_cast<typename _C::size_type>(__last - __first), __value_);
}
// copy
Index: include/limits
===================================================================
--- include/limits (revision 142723)
+++ include/limits (working copy)
@@ -109,6 +109,10 @@
#include <__config>
#include <type_traits>
+#if defined(_MSC_VER)
+#include "support/win32/limits_win32.h"
+#endif // _MSC_VER
+
_LIBCPP_BEGIN_NAMESPACE_STD
enum float_round_style
Index: include/string
===================================================================
--- include/string (revision 142723)
+++ include/string (working copy)
@@ -1023,7 +1023,14 @@
#endif
}
+#ifdef _MSC_VER
+#pragma warning( push )
+#pragma warning( disable: 4231 )
+#endif // _MSC_VER
extern template class __basic_string_common<true>;
+#ifdef _MSC_VER
+#pragma warning( pop )
+#endif // _MSC_VER
template<class _CharT, class _Traits, class _Allocator>
class _LIBCPP_VISIBLE basic_string
Index: include/algorithm
===================================================================
--- include/algorithm (revision 142723)
+++ include/algorithm (working copy)
@@ -764,10 +764,10 @@
template <class _InputIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_InputIterator
-find(_InputIterator __first, _InputIterator __last, const _Tp& __value)
+find(_InputIterator __first, _InputIterator __last, const _Tp& __value_)
{
for (; __first != __last; ++__first)
- if (*__first == __value)
+ if (*__first == __value_)
break;
return __first;
}
@@ -1004,11 +1004,11 @@
template <class _InputIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename iterator_traits<_InputIterator>::difference_type
-count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
+count(_InputIterator __first, _InputIterator __last, const _Tp& __value_)
{
typename iterator_traits<_InputIterator>::difference_type __r(0);
for (; __first != __last; ++__first)
- if (*__first == __value)
+ if (*__first == __value_)
++__r;
return __r;
}
@@ -1312,22 +1312,22 @@
template <class _BinaryPredicate, class _ForwardIterator, class _Size, class _Tp>
_ForwardIterator
__search_n(_ForwardIterator __first, _ForwardIterator __last,
- _Size __count, const _Tp& __value, _BinaryPredicate __pred, forward_iterator_tag)
+ _Size __count, const _Tp& __value_, _BinaryPredicate __pred, forward_iterator_tag)
{
if (__count <= 0)
return __first;
while (true)
{
- // Find first element in sequence that matchs __value, with a mininum of loop checks
+ // Find first element in sequence that matchs __value_, with a mininum of loop checks
while (true)
{
- if (__first == __last) // return __last if no element matches __value
+ if (__first == __last) // return __last if no element matches __value_
return __last;
- if (__pred(*__first, __value))
+ if (__pred(*__first, __value_))
break;
++__first;
}
- // *__first matches __value, now match elements after here
+ // *__first matches __value_, now match elements after here
_ForwardIterator __m = __first;
_Size __c(0);
while (true)
@@ -1336,7 +1336,7 @@
return __first;
if (++__m == __last) // Otherwise if source exhaused, pattern not found
return __last;
- if (!__pred(*__m, __value)) // if there is a mismatch, restart with a new __first
+ if (!__pred(*__m, __value_)) // if there is a mismatch, restart with a new __first
{
__first = __m;
++__first;
@@ -1349,7 +1349,7 @@
template <class _BinaryPredicate, class _RandomAccessIterator, class _Size, class _Tp>
_RandomAccessIterator
__search_n(_RandomAccessIterator __first, _RandomAccessIterator __last,
- _Size __count, const _Tp& __value, _BinaryPredicate __pred, random_access_iterator_tag)
+ _Size __count, const _Tp& __value_, _BinaryPredicate __pred, random_access_iterator_tag)
{
if (__count <= 0)
return __first;
@@ -1359,16 +1359,16 @@
const _RandomAccessIterator __s = __last - (__count - 1); // Start of pattern match can't go beyond here
while (true)
{
- // Find first element in sequence that matchs __value, with a mininum of loop checks
+ // Find first element in sequence that matchs __value_, with a mininum of loop checks
while (true)
{
if (__first == __s) // return __last if no element matches __value
return __last;
- if (__pred(*__first, __value))
+ if (__pred(*__first, __value_))
break;
++__first;
}
- // *__first matches __value, now match elements after here
+ // *__first matches __value_, now match elements after here
_RandomAccessIterator __m = __first;
_Size __c(0);
while (true)
@@ -1376,7 +1376,7 @@
if (++__c == __count) // If pattern exhausted, __first is the answer (works for 1 element pattern)
return __first;
++__m; // no need to check range on __m because __s guarantees we have enough source
- if (!__pred(*__m, __value)) // if there is a mismatch, restart with a new __first
+ if (!__pred(*__m, __value_)) // if there is a mismatch, restart with a new __first
{
__first = __m;
++__first;
@@ -1390,19 +1390,19 @@
inline _LIBCPP_INLINE_VISIBILITY
_ForwardIterator
search_n(_ForwardIterator __first, _ForwardIterator __last,
- _Size __count, const _Tp& __value, _BinaryPredicate __pred)
+ _Size __count, const _Tp& __value_, _BinaryPredicate __pred)
{
return _VSTD::__search_n<typename add_lvalue_reference<_BinaryPredicate>::type>
- (__first, __last, __count, __value, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
+ (__first, __last, __count, __value_, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
}
template <class _ForwardIterator, class _Size, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_ForwardIterator
-search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value)
+search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value_)
{
typedef typename iterator_traits<_ForwardIterator>::value_type __v;
- return _VSTD::search_n(__first, __last, __count, __value, __equal_to<__v, _Tp>());
+ return _VSTD::search_n(__first, __last, __count, __value_, __equal_to<__v, _Tp>());
}
// copy
@@ -1744,29 +1744,29 @@
template <class _OutputIterator, class _Size, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
-__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value, false_type)
+__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_, false_type)
{
for (; __n > 0; ++__first, --__n)
- *__first = __value;
+ *__first = __value_;
return __first;
}
template <class _OutputIterator, class _Size, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
-__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value, true_type)
+__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_, true_type)
{
if (__n > 0)
- _VSTD::memset(__first, (unsigned char)__value, (size_t)(__n));
+ _VSTD::memset(__first, (unsigned char)__value_, (size_t)(__n));
return __first + __n;
}
template <class _OutputIterator, class _Size, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
-fill_n(_OutputIterator __first, _Size __n, const _Tp& __value)
+fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_)
{
- return _VSTD::__fill_n(__first, __n, __value, integral_constant<bool,
+ return _VSTD::__fill_n(__first, __n, __value_, integral_constant<bool,
is_pointer<_OutputIterator>::value &&
is_trivially_copy_assignable<_Tp>::value &&
sizeof(_Tp) == 1>());
@@ -1777,26 +1777,26 @@
template <class _ForwardIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
void
-__fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, forward_iterator_tag)
+__fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, forward_iterator_tag)
{
for (; __first != __last; ++__first)
- *__first = __value;
+ *__first = __value_;
}
template <class _RandomAccessIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
void
-__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value, random_access_iterator_tag)
+__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value_, random_access_iterator_tag)
{
- _VSTD::fill_n(__first, __last - __first, __value);
+ _VSTD::fill_n(__first, __last - __first, __value_);
}
template <class _ForwardIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
void
-fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
+fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
- _VSTD::__fill(__first, __last, __value, typename iterator_traits<_ForwardIterator>::iterator_category());
+ _VSTD::__fill(__first, __last, __value_, typename iterator_traits<_ForwardIterator>::iterator_category());
}
// generate
@@ -1826,15 +1826,15 @@
template <class _ForwardIterator, class _Tp>
_ForwardIterator
-remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
+remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
- __first = _VSTD::find(__first, __last, __value);
+ __first = _VSTD::find(__first, __last, __value_);
if (__first != __last)
{
_ForwardIterator __i = __first;
while (++__i != __last)
{
- if (!(*__i == __value))
+ if (!(*__i == __value_))
{
*__first = _VSTD::move(*__i);
++__first;
@@ -1872,11 +1872,11 @@
template <class _InputIterator, class _OutputIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
-remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value)
+remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value_)
{
for (; __first != __last; ++__first)
{
- if (!(*__first == __value))
+ if (!(*__first == __value_))
{
*__result = *__first;
++__result;
@@ -3683,6 +3683,10 @@
_VSTD::sort<_Tp*, _Comp_ref>(__first.base(), __last.base(), __comp);
}
+#ifdef _MSC_VER
+#pragma warning( push )
+#pragma warning( disable: 4231)
+#endif // _MSC_VER
extern template void __sort<__less<char>&, char*>(char*, char*, __less<char>&);
extern template void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
extern template void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
@@ -3716,12 +3720,15 @@
extern template bool __insertion_sort_incomplete<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
extern template unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&);
+#ifdef _MSC_VER
+#pragma warning( pop )
+#endif _MSC_VER
// lower_bound
template <class _Compare, class _ForwardIterator, class _Tp>
_ForwardIterator
-__lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
+__lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
difference_type __len = _VSTD::distance(__first, __last);
@@ -3730,7 +3737,7 @@
difference_type __l2 = __len / 2;
_ForwardIterator __m = __first;
_VSTD::advance(__m, __l2);
- if (__comp(*__m, __value))
+ if (__comp(*__m, __value_))
{
__first = ++__m;
__len -= __l2 + 1;
@@ -3744,24 +3751,24 @@
template <class _ForwardIterator, class _Tp, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
_ForwardIterator
-lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
+lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
#ifdef _LIBCPP_DEBUG2
typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
__debug_less<_Compare> __c(__comp);
- return __lower_bound<_Comp_ref>(__first, __last, __value, __c);
+ return __lower_bound<_Comp_ref>(__first, __last, __value_, __c);
#else // _LIBCPP_DEBUG2
typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
- return __lower_bound<_Comp_ref>(__first, __last, __value, __comp);
+ return __lower_bound<_Comp_ref>(__first, __last, __value_, __comp);
#endif // _LIBCPP_DEBUG2
}
template <class _ForwardIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_ForwardIterator
-lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
+lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
- return _VSTD::lower_bound(__first, __last, __value,
+ return _VSTD::lower_bound(__first, __last, __value_,
__less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
}
@@ -3769,7 +3776,7 @@
template <class _Compare, class _ForwardIterator, class _Tp>
_ForwardIterator
-__upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
+__upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
difference_type __len = _VSTD::distance(__first, __last);
@@ -3778,7 +3785,7 @@
difference_type __l2 = __len / 2;
_ForwardIterator __m = __first;
_VSTD::advance(__m, __l2);
- if (__comp(__value, *__m))
+ if (__comp(__value_, *__m))
__len = __l2;
else
{
@@ -3792,24 +3799,24 @@
template <class _ForwardIterator, class _Tp, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
_ForwardIterator
-upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
+upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
#ifdef _LIBCPP_DEBUG2
typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
__debug_less<_Compare> __c(__comp);
- return __upper_bound<_Comp_ref>(__first, __last, __value, __c);
+ return __upper_bound<_Comp_ref>(__first, __last, __value_, __c);
#else // _LIBCPP_DEBUG2
typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
- return __upper_bound<_Comp_ref>(__first, __last, __value, __comp);
+ return __upper_bound<_Comp_ref>(__first, __last, __value_, __comp);
#endif // _LIBCPP_DEBUG2
}
template <class _ForwardIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_ForwardIterator
-upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
+upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
- return _VSTD::upper_bound(__first, __last, __value,
+ return _VSTD::upper_bound(__first, __last, __value_,
__less<_Tp, typename iterator_traits<_ForwardIterator>::value_type>());
}
@@ -3817,7 +3824,7 @@
template <class _Compare, class _ForwardIterator, class _Tp>
pair<_ForwardIterator, _ForwardIterator>
-__equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
+__equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
difference_type __len = _VSTD::distance(__first, __last);
@@ -3826,12 +3833,12 @@
difference_type __l2 = __len / 2;
_ForwardIterator __m = __first;
_VSTD::advance(__m, __l2);
- if (__comp(*__m, __value))
+ if (__comp(*__m, __value_))
{
__first = ++__m;
__len -= __l2 + 1;
}
- else if (__comp(__value, *__m))
+ else if (__comp(__value_, *__m))
{
__last = __m;
__len = __l2;
@@ -3841,8 +3848,8 @@
_ForwardIterator __mp1 = __m;
return pair<_ForwardIterator, _ForwardIterator>
(
- __lower_bound<_Compare>(__first, __m, __value, __comp),
- __upper_bound<_Compare>(++__mp1, __last, __value, __comp)
+ __lower_bound<_Compare>(__first, __m, __value_, __comp),
+ __upper_bound<_Compare>(++__mp1, __last, __value_, __comp)
);
}
}
@@ -3852,24 +3859,24 @@
template <class _ForwardIterator, class _Tp, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
pair<_ForwardIterator, _ForwardIterator>
-equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
+equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
#ifdef _LIBCPP_DEBUG2
typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
__debug_less<_Compare> __c(__comp);
- return __equal_range<_Comp_ref>(__first, __last, __value, __c);
+ return __equal_range<_Comp_ref>(__first, __last, __value_, __c);
#else // _LIBCPP_DEBUG2
typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
- return __equal_range<_Comp_ref>(__first, __last, __value, __comp);
+ return __equal_range<_Comp_ref>(__first, __last, __value_, __comp);
#endif // _LIBCPP_DEBUG2
}
template <class _ForwardIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
pair<_ForwardIterator, _ForwardIterator>
-equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
+equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
- return _VSTD::equal_range(__first, __last, __value,
+ return _VSTD::equal_range(__first, __last, __value_,
__less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
}
@@ -3878,33 +3885,33 @@
template <class _Compare, class _ForwardIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool
-__binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
+__binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
- __first = __lower_bound<_Compare>(__first, __last, __value, __comp);
- return __first != __last && !__comp(__value, *__first);
+ __first = __lower_bound<_Compare>(__first, __last, __value_, __comp);
+ return __first != __last && !__comp(__value_, *__first);
}
template <class _ForwardIterator, class _Tp, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
bool
-binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp)
+binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
#ifdef _LIBCPP_DEBUG2
typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref;
__debug_less<_Compare> __c(__comp);
- return __binary_search<_Comp_ref>(__first, __last, __value, __c);
+ return __binary_search<_Comp_ref>(__first, __last, __value_, __c);
#else // _LIBCPP_DEBUG2
typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
- return __binary_search<_Comp_ref>(__first, __last, __value, __comp);
+ return __binary_search<_Comp_ref>(__first, __last, __value_, __comp);
#endif // _LIBCPP_DEBUG2
}
template <class _ForwardIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool
-binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
+binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
- return _VSTD::binary_search(__first, __last, __value,
+ return _VSTD::binary_search(__first, __last, __value_,
__less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
}
Index: include/vector
===================================================================
--- include/vector (revision 142723)
+++ include/vector (working copy)
@@ -307,7 +307,14 @@
#endif
}
+#ifdef _MSC_VER
+#pragma warning( push )
+#pragma warning( disable: 4231 )
+#endif // _MSC_VER
extern template class __vector_base_common<true>;
+#ifdef _MSC_VER
+#pragma warning( pop )
+#endif // _MSC_VER
template <class _Tp, class _Allocator>
class __vector_base
Index: include/__config
===================================================================
--- include/__config (revision 142723)
+++ include/__config (working copy)
@@ -321,6 +321,8 @@
#elif defined(_MSC_VER)
+#define _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES
#define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
#define _LIBCPP_HAS_NO_CONSTEXPR
#define _LIBCPP_HAS_NO_UNICODE_CHARS
Index: include/cstring
===================================================================
--- include/cstring (revision 142723)
+++ include/cstring (working copy)
@@ -93,7 +93,8 @@
using ::strstr;
-#ifndef __GLIBC__ // GNU libc and its derivates already have the correct prototype in <string.h> #ifdef __cplusplus
+// MSVC, GNU libc and its derivates already have the correct prototype in <string.h> #ifdef __cplusplus
+#if !defined(__GLIBC__) && !defined(_MSC_VER)
inline _LIBCPP_INLINE_VISIBILITY char* strchr( char* __s, int __c) {return ::strchr(__s, __c);}
inline _LIBCPP_INLINE_VISIBILITY char* strpbrk( char* __s1, const char* __s2) {return ::strpbrk(__s1, __s2);}
inline _LIBCPP_INLINE_VISIBILITY char* strrchr( char* __s, int __c) {return ::strrchr(__s, __c);}
Index: include/support/win32/support.h
===================================================================
--- include/support/win32/support.h (revision 142723)
+++ include/support/win32/support.h (working copy)
@@ -15,17 +15,81 @@
Functions and constants used in libc++ that are missing from the Windows C library.
*/
+#include <__config>
#include <wchar.h> // mbstate_t
#include <stdio.h> // _snwprintf
#define swprintf _snwprintf
#define vswprintf _vsnwprintf
+#define vfscnaf fscanf
-int vasprintf( char **sptr, const char *__restrict__ fmt , va_list ap );
-int asprintf(char **sptr, const char *__restrict__ fmt, ...);
+int vasprintf( char **sptr, const char *__restrict fmt , va_list ap );
+int asprintf( char **sptr, const char *__restrict fmt, ...);
+//int vfscanf( FILE *__restrict stream, const char *__restrict format,
+// va_list arg);
-size_t mbsnrtowcs( wchar_t *__restrict__ dst, const char **__restrict__ src,
- size_t nmc, size_t len, mbstate_t *__restrict__ ps );
-size_t wcsnrtombs( char *__restrict__ dst, const wchar_t **__restrict__ src,
- size_t nwc, size_t len, mbstate_t *__restrict__ ps );
+size_t mbsnrtowcs( wchar_t *__restrict dst, const char **__restrict src,
+ size_t nmc, size_t len, mbstate_t *__restrict ps );
+size_t wcsnrtombs( char *__restrict dst, const wchar_t **__restrict src,
+ size_t nwc, size_t len, mbstate_t *__restrict ps );
+
+#if defined(_MSC_VER)
+#define snprintf _snprintf
+inline int isblank( int c, locale_t /*loc*/ )
+{ return ( c == ' ' || c == '\t' ); }
+inline int iswblank( wint_t c, locale_t /*loc*/ )
+{ return ( c == L' ' || c == L'\t' ); }
+#include <xlocinfo.h>
+#define atoll _atoi64
+#define strtoll _strtoi64
+#define strtoull _strtoui64
+#define wcstoll _wcstoi64
+#define wcstoull _wcstoui64
+_LIBCPP_ALWAYS_INLINE float strtof( const char *nptr, char **endptr )
+{ return _Stof(nptr, endptr, 0); }
+_LIBCPP_ALWAYS_INLINE double strtod( const char *nptr, char **endptr )
+{ return _Stod(nptr, endptr, 0); }
+_LIBCPP_ALWAYS_INLINE long double strtold( const char *nptr, char **endptr )
+{ return _Stold(nptr, endptr, 0); }
+_LIBCPP_ALWAYS_INLINE float wcstof( const wchar_t *nptr, char** endptr )
+#define _Exit _exit
+
+#include <intrin.h>
+#define __builtin_popcount __popcnt
+#define __builtin_popcountl __popcnt
+#define __builtin_popcountll(__i) static_cast<int>(__popcnt64(__i))
+
+_LIBCPP_ALWAYS_INLINE int __builtin_ctz( unsigned int x )
+{
+ DWORD r = 0;
+ _BitScanReverse(&r, x);
+ return static_cast<int>(r);
+}
+// sizeof(long) == sizeof(int) on Windows
+_LIBCPP_ALWAYS_INLINE int __builtin_ctzl( unsigned long x )
+{ return __builtin_ctz( static_cast<int>(x) ); }
+_LIBCPP_ALWAYS_INLINE int __builtin_ctzll( unsigned long long x )
+{
+ DWORD r = 0;
+ _BitScanReverse64(&r, x);
+ return static_cast<int>(r);
+}
+_LIBCPP_ALWAYS_INLINE int __builtin_clz( unsigned int x )
+{
+ DWORD r = 0;
+ _BitScanForward(&r, x);
+ return static_cast<int>(r);
+}
+// sizeof(long) == sizeof(int) on Windows
+_LIBCPP_ALWAYS_INLINE int __builtin_clzl( unsigned long x )
+{ return __builtin_clz( static_cast<int>(x) ); }
+_LIBCPP_ALWAYS_INLINE int __builtin_clzll( unsigned long long x )
+{
+ DWORD r = 0;
+ _BitScanForward64(&r, x);
+ return static_cast<int>(r);
+}
+
+#endif
+
#endif // _LIBCPP_SUPPORT_WIN32_SUPPORT_H
\ No newline at end of file
Index: include/support/win32/limits_win32.h
===================================================================
--- include/support/win32/limits_win32.h (revision 142723)
+++ include/support/win32/limits_win32.h (working copy)
@@ -15,6 +15,11 @@
#error "This header is MSVC specific, Clang and GCC should not include it"
#else
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+#include <windows.h> // ymath.h works correctly
+
#include <float.h> // limit constants
#define __FLT_MANT_DIG__ FLT_MANT_DIG
@@ -57,16 +62,17 @@
#define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L
// __builtin replacements/workarounds
+#include <math.h> // HUGE_VAL
#include <ymath.h> // internal MSVC header providing the needed functionality
-#define __builtin_huge_val() HUGE_VAL
-#define __builtin_huge_valf() _FInf
-#define __builtin_huge_vall() _LInf
-#define __builtin_nan() _Nan
-#define __builtin_nanf() _FNan
-#define __builtin_nanl() _LNan
-#define __builtin_nans() _Snan
-#define __builtin_nansf() _FSnan
-#define __builtin_nansl() _LSnan
+#define __builtin_huge_val() HUGE_VAL
+#define __builtin_huge_valf() _FInf._Float
+#define __builtin_huge_vall() _LInf._Long_double
+#define __builtin_nan(__dummy) _Nan._Double
+#define __builtin_nanf(__dummy) _FNan._Float
+#define __builtin_nanl(__dummmy) _LNan._Long_double
+#define __builtin_nans(__dummy) _Snan._Double
+#define __builtin_nansf(__dummy) _FSnan._Float
+#define __builtin_nansl(__dummy) _LSnan._Long_double
#endif // _MSC_VER
Index: src/support/win32/support.cpp
===================================================================
--- src/support/win32/support.cpp (revision 142723)
+++ src/support/win32/support.cpp (working copy)
@@ -15,7 +15,7 @@
#include <stdio.h> // vsprintf, vsnprintf
#include <string.h> // strcpy, wcsncpy
-int asprintf(char **sptr, const char *__restrict__ fmt, ...)
+int asprintf(char **sptr, const char *__restrict fmt, ...)
{
va_list ap;
va_start(ap, fmt);
@@ -23,7 +23,7 @@
va_end(ap);
return result;
}
-int vasprintf( char **sptr, const char *__restrict__ fmt, va_list ap )
+int vasprintf( char **sptr, const char *__restrict fmt, va_list ap )
{
*sptr = NULL;
int count = vsnprintf( *sptr, 0, fmt, ap );
@@ -38,8 +38,8 @@
// FIXME: use wcrtomb and avoid copy
// use mbsrtowcs which is available, first copy first nwc elements of src
-size_t mbsnrtowcs( wchar_t *__restrict__ dst, const char **__restrict__ src,
- size_t nmc, size_t len, mbstate_t *__restrict__ ps )
+size_t mbsnrtowcs( wchar_t *__restrict dst, const char **__restrict src,
+ size_t nmc, size_t len, mbstate_t *__restrict ps )
{
char* local_src = new char[nmc+1];
char* nmcsrc = local_src;
@@ -54,8 +54,8 @@
}
// FIXME: use wcrtomb and avoid copy
// use wcsrtombs which is available, first copy first nwc elements of src
-size_t wcsnrtombs( char *__restrict__ dst, const wchar_t **__restrict__ src,
- size_t nwc, size_t len, mbstate_t *__restrict__ ps )
+size_t wcsnrtombs( char *__restrict dst, const wchar_t **__restrict src,
+ size_t nwc, size_t len, mbstate_t *__restrict ps )
{
wchar_t* local_src = new wchar_t[nwc];
wchar_t* nwcsrc = local_src;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: algorithm.cpp
Type: text/x-c++src
Size: 4333 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20111022/c6eae9a0/attachment.cpp>
More information about the cfe-dev
mailing list