Index: include/__config
===================================================================
--- include/__config	(revision 188239)
+++ include/__config	(working copy)
@@ -418,6 +418,7 @@
 #define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
 #define _LIBCPP_HAS_NO_CONSTEXPR
 #define _LIBCPP_HAS_NO_UNICODE_CHARS
+#define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
 #define _LIBCPP_HAS_NO_DELETED_FUNCTIONS
 #define __alignof__ __alignof
 #define _LIBCPP_NORETURN __declspec(noreturn)
Index: include/algorithm
===================================================================
--- include/algorithm	(revision 188239)
+++ include/algorithm	(working copy)
@@ -634,6 +634,10 @@
 #pragma GCC system_header
 #endif
 
+#ifdef _LIBCPP_MSVCRT
+#include "support\win32\support.h" // __builtin
+#endif
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _T1, class _T2 = _T1>
Index: include/cmath
===================================================================
--- include/cmath	(revision 188239)
+++ include/cmath	(working copy)
@@ -1678,11 +1678,8 @@
 using ::tgammal;
 using ::truncl;
 #endif // !_LIBCPP_MSVCRT
-
-#else 
 using ::lgamma;
 using ::lgammaf;
 #endif // __sun__
 _LIBCPP_END_NAMESPACE_STD
-
 #endif  // _LIBCPP_CMATH
Index: include/cstdio
===================================================================
--- include/cstdio	(revision 188239)
+++ include/cstdio	(working copy)
@@ -135,7 +135,9 @@
 using ::fscanf;
 using ::printf;
 using ::scanf;
+#ifndef _LIBCPP_MSVCRT
 using ::snprintf;
+#endif
 using ::sprintf;
 using ::sscanf;
 #ifndef _LIBCPP_MSVCRT
Index: include/cstdlib
===================================================================
--- include/cstdlib	(revision 188239)
+++ include/cstdlib	(working copy)
@@ -85,7 +85,7 @@
 #include <__config>
 #include <stdlib.h>
 #ifdef _LIBCPP_MSVCRT
-#include "support/win32/locale_win32.h"
+#include "support/win32/support.h"
 #endif // _LIBCPP_MSVCRT
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Index: include/support/win32/limits_win32.h
===================================================================
--- include/support/win32/limits_win32.h	(revision 188239)
+++ include/support/win32/limits_win32.h	(working copy)
@@ -15,13 +15,11 @@
 #error "This header complements Microsoft's C Runtime library, and should not be included otherwise."
 #else
 
-#ifndef NOMINMAX
-#define NOMINMAX
-#endif
-#include <windows.h> // ymath.h works correctly
+// These are built-in's for clang etc. Provide them for the genuine ms compiler.
+#if _MSC_VER && !__clang__
+#include <float.h> // FLT_ etc.
+#include <limits.h> // CHAR_BIT
 
-#include <float.h> // limit constants
-
 #define __FLT_MANT_DIG__   FLT_MANT_DIG
 #define __FLT_DIG__        FLT_DIG
 #define __FLT_RADIX__      FLT_RADIX
@@ -60,7 +58,7 @@
 #define __LDBL_EPSILON__    LDBL_EPSILON
 // predefined by MinGW GCC
 #define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L
-
+#define __CHAR_BIT__        CHAR_BIT
 // __builtin replacements/workarounds
 #include <math.h> // HUGE_VAL
 #include <ymath.h> // internal MSVC header providing the needed functionality
@@ -74,6 +72,6 @@
 #define __builtin_nansf(__dummy) _FSnan._Float
 #define __builtin_nansl(__dummy) _LSnan._Long_double
 
+#endif // _MSC_VER && !__clang__
 #endif // _LIBCPP_MSVCRT
-
 #endif // _LIBCPP_SUPPORT_WIN32_LIMITS_WIN32_H
Index: include/support/win32/locale_win32.h
===================================================================
--- include/support/win32/locale_win32.h	(revision 188239)
+++ include/support/win32/locale_win32.h	(working copy)
@@ -11,10 +11,12 @@
 #ifndef _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H
 #define _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H
 
+#if !defined(_LIBCPP_MSVCRT)
+#error "This header complements Microsoft's C Runtime library, and should not be included otherwise."
+#else
 // ctype mask table defined in msvcrt.dll
 extern "C" unsigned short  __declspec(dllimport) _ctype[];
 
-#include "support/win32/support.h"
 #include <memory>
 #include <xlocinfo.h> // _locale_t
 #define locale_t _locale_t
@@ -35,22 +37,22 @@
 locale_t newlocale( int mask, const char * locale, locale_t base );
 locale_t uselocale( locale_t newloc );
 lconv *localeconv_l( locale_t loc );
-size_t mbrlen_l( const char *__restrict__ s, size_t n,
-                 mbstate_t *__restrict__ ps, locale_t loc);
-size_t mbsrtowcs_l( wchar_t *__restrict__ dst, const char **__restrict__ src,
-                    size_t len, mbstate_t *__restrict__ ps, locale_t loc );
-size_t wcrtomb_l( char *__restrict__ s, wchar_t wc, mbstate_t *__restrict__ ps,
+size_t mbrlen_l( const char *__restrict s, size_t n,
+                 mbstate_t *__restrict ps, locale_t loc);
+size_t mbsrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
+                    size_t len, mbstate_t *__restrict ps, locale_t loc );
+size_t wcrtomb_l( char *__restrict s, wchar_t wc, mbstate_t *__restrict ps,
                   locale_t loc);
-size_t mbrtowc_l( wchar_t *__restrict__ pwc, const char *__restrict__ s,
-                  size_t n, mbstate_t *__restrict__ ps, locale_t loc);
-size_t mbsnrtowcs_l( wchar_t *__restrict__ dst, const char **__restrict__ src,
-                     size_t nms, size_t len, mbstate_t *__restrict__ ps, locale_t loc);
-size_t wcsnrtombs_l( char *__restrict__ dst, const wchar_t **__restrict__ src,
-                     size_t nwc, size_t len, mbstate_t *__restrict__ ps, locale_t loc);
+size_t mbrtowc_l( wchar_t *__restrict pwc, const char *__restrict s,
+                  size_t n, mbstate_t *__restrict ps, locale_t loc);
+size_t mbsnrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
+                     size_t nms, size_t len, mbstate_t *__restrict ps, locale_t loc);
+size_t wcsnrtombs_l( char *__restrict dst, const wchar_t **__restrict src,
+                     size_t nwc, size_t len, mbstate_t *__restrict ps, locale_t loc);
 wint_t btowc_l( int c, locale_t loc );
 int wctob_l( wint_t c, locale_t loc );
-typedef _VSTD::remove_pointer<locale_t>::type __locale_struct;
-typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii;
+typedef std::remove_pointer<locale_t>::type __locale_struct;
+typedef std::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii;
 _LIBCPP_ALWAYS_INLINE inline
 decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
 {
@@ -126,4 +128,5 @@
 inline int iswblank( wint_t c, locale_t /*loc*/ )
 { return ( c == L' ' || c == L'\t' ); }
 #endif // _MSC_VER
+#endif
 #endif // _LIBCPP_SUPPORT_WIN32_LOCALE_WIN32_H
Index: include/support/win32/math_win32.h
===================================================================
--- include/support/win32/math_win32.h	(revision 188239)
+++ include/support/win32/math_win32.h	(working copy)
@@ -15,7 +15,12 @@
 #error "This header complements Microsoft's C Runtime library, and should not be included otherwise."
 #else
 
-#include <math.h>
+// Not sure who needs support here for isfinite etc now.
+// Later compilers and libraries like VS2013 and GNU
+// seem to support them now and clang it's built in, 
+// So leave out for now. Re-instate if needed.
+#if 0 
+#include <float.h>
 
 typedef float float_t;
 typedef double double_t;
@@ -107,7 +112,6 @@
 {
     return _fpclass(num);
 }
-
+#endif // 0
 #endif // _LIBCPP_MSVCRT
-
 #endif // _LIBCPP_SUPPORT_WIN32_MATH_WIN32_H
Index: include/support/win32/support.h
===================================================================
--- include/support/win32/support.h	(revision 188239)
+++ include/support/win32/support.h	(working copy)
@@ -11,6 +11,9 @@
 #ifndef _LIBCPP_SUPPORT_WIN32_SUPPORT_H
 #define _LIBCPP_SUPPORT_WIN32_SUPPORT_H
 
+#if !defined(_LIBCPP_MSVCRT)
+#error "This header complements Microsoft's C Runtime library, and should not be included otherwise."
+#else
 /*
    Functions and constants used in libc++ that are missing from the Windows C library.
   */
@@ -17,9 +20,17 @@
 
 #include <cwchar>  // mbstate_t
 #include <cstdarg> // va_ macros
-#define swprintf _snwprintf
-#define vswprintf _vsnwprintf
 
+#if (__GNUC__ || _MSC_VER) && ! __clang__
+#include <intrin.h> // BitScanForward64
+#endif
+
+#include <xlocinfo.h>
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+#include <Windows.h>
+
 extern "C" {
 
 int vasprintf( char **sptr, const char *__restrict fmt, va_list ap );
@@ -30,25 +41,17 @@
                    size_t nwc, size_t len, mbstate_t *__restrict ps );
 }
 
-#if defined(_LIBCPP_MSVCRT)
+#define swprintf _snwprintf
+#define vswprintf _vsnwprintf
 #define snprintf _snprintf
-#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); }
-
 #define _Exit _exit
 
-#ifndef __clang__ // MSVC-based Clang also defines _MSC_VER
-#include <intrin.h>
+#if _MSC_VER && !__clang__ // clang supports these intrinsics.
 
 _LIBCPP_ALWAYS_INLINE int __builtin_popcount(unsigned int x) {
    static const unsigned int m1 = 0x55555555; //binary: 0101...
@@ -105,10 +108,10 @@
 _LIBCPP_ALWAYS_INLINE int __builtin_clzll( unsigned long long x )
 {
     DWORD r = 0;
-    _BitScanForward64(&r, x);
+    _BitScanForward64(&r, x); // Note intrinsic only available on 64 bit compiler.
     return static_cast<int>(r);
 }
-#endif // !__clang__
-#endif // _LIBCPP_MSVCRT
+#endif // _MSC_VER && !__clang__
+#endif
+#endif // _LIBCPP_SUPPORT_WIN32_SUPPORT_H
 
-#endif // _LIBCPP_SUPPORT_WIN32_SUPPORT_H
Index: src/debug.cpp
===================================================================
--- src/debug.cpp	(revision 188239)
+++ src/debug.cpp	(working copy)
@@ -9,7 +9,7 @@
 
 #define _LIBCPP_DEBUG2 1
 #include "__config"
-#include "__debug"
+//#include "__debug"
 #include "functional"
 #include "algorithm"
 #include "__hash_table"
Index: src/support/win32/locale_win32.cpp
===================================================================
--- src/support/win32/locale_win32.cpp	(revision 188239)
+++ src/support/win32/locale_win32.cpp	(working copy)
@@ -8,9 +8,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "support/win32/locale_win32.h"
 #include <cstdarg> // va_start, va_end
 #include <cwchar>  // mbstate_t
+#include "support/win32/locale_win32.h"
 
 // FIXME: base currently unused. Needs manual work to construct the new locale
 locale_t newlocale( int mask, const char * locale, locale_t /*base*/ )
@@ -34,38 +34,38 @@
     __locale_raii __current( uselocale(loc), uselocale );
     return localeconv();
 }
-size_t mbrlen_l( const char *__restrict__ s, size_t n,
-                 mbstate_t *__restrict__ ps, locale_t loc )
+size_t mbrlen_l( const char *__restrict s, size_t n,
+                 mbstate_t *__restrict ps, locale_t loc )
 {
     __locale_raii __current( uselocale(loc), uselocale );
     return mbrlen( s, n, ps );
 }
-size_t mbsrtowcs_l( wchar_t *__restrict__ dst, const char **__restrict__ src,
-                    size_t len, mbstate_t *__restrict__ ps, locale_t loc )
+size_t mbsrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
+                    size_t len, mbstate_t *__restrict ps, locale_t loc )
 {
     __locale_raii __current( uselocale(loc), uselocale );
     return mbsrtowcs( dst, src, len, ps );
 }
-size_t wcrtomb_l( char *__restrict__ s, wchar_t wc, mbstate_t *__restrict__ ps,
+size_t wcrtomb_l( char *__restrict s, wchar_t wc, mbstate_t *__restrict ps,
                   locale_t loc )
 {
     __locale_raii __current( uselocale(loc), uselocale );
     return wcrtomb( s, wc, ps );
 }
-size_t mbrtowc_l( wchar_t *__restrict__ pwc, const char *__restrict__ s,
-                  size_t n, mbstate_t *__restrict__ ps, locale_t loc )
+size_t mbrtowc_l( wchar_t *__restrict pwc, const char *__restrict s,
+                  size_t n, mbstate_t *__restrict ps, locale_t loc )
 {
     __locale_raii __current( uselocale(loc), uselocale );
     return mbrtowc( pwc, s, n, ps );
 }
-size_t mbsnrtowcs_l( wchar_t *__restrict__ dst, const char **__restrict__ src,
-                     size_t nms, size_t len, mbstate_t *__restrict__ ps, locale_t loc )
+size_t mbsnrtowcs_l( wchar_t *__restrict dst, const char **__restrict src,
+                     size_t nms, size_t len, mbstate_t *__restrict ps, locale_t loc )
 {
     __locale_raii __current( uselocale(loc), uselocale );
     return mbsnrtowcs( dst, src, nms, len, ps );
 }
-size_t wcsnrtombs_l( char *__restrict__ dst, const wchar_t **__restrict__ src,
-                     size_t nwc, size_t len, mbstate_t *__restrict__ ps, locale_t loc )
+size_t wcsnrtombs_l( char *__restrict dst, const wchar_t **__restrict src,
+                     size_t nwc, size_t len, mbstate_t *__restrict ps, locale_t loc )
 {
     __locale_raii __current( uselocale(loc), uselocale );
     return wcsnrtombs( dst, src, nwc, len, ps );
