Index: include/__config
===================================================================
--- include/__config	(revision 188457)
+++ include/__config	(working copy)
@@ -419,12 +419,15 @@
 #define _LIBCPP_HAS_NO_CONSTEXPR
 #define _LIBCPP_HAS_NO_UNICODE_CHARS
 #define _LIBCPP_HAS_NO_DELETED_FUNCTIONS
+#define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
 #define __alignof__ __alignof
 #define _LIBCPP_NORETURN __declspec(noreturn)
 #define _ALIGNAS(x) __declspec(align(x))
 #define _LIBCPP_HAS_NO_VARIADICS
 
-#define _NOEXCEPT throw()
+// FIXME consider picking these up from yvals.h to avoid redefinition warnings
+// where using the real cl.exe
+#define _NOEXCEPT throw ()
 #define _NOEXCEPT_(x)
 
 #define _LIBCPP_BEGIN_NAMESPACE_STD namespace std {
Index: include/algorithm
===================================================================
--- include/algorithm	(revision 188457)
+++ include/algorithm	(working copy)
@@ -638,6 +638,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 188457)
+++ include/cmath	(working copy)
@@ -1680,11 +1680,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 188457)
+++ 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 188457)
+++ 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 188457)
+++ 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 188457)
+++ include/support/win32/locale_win32.h	(working copy)
@@ -11,10 +11,13 @@
 #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 <stdio.h>
 #include <memory>
 #include <xlocinfo.h> // _locale_t
 #define locale_t _locale_t
@@ -35,22 +38,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 )
 {
@@ -59,7 +62,6 @@
 }
 
 // the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+
-#include <stdio.h>
 #define mbtowc_l _mbtowc_l
 #define strtoll_l _strtoi64_l
 #define strtoull_l _strtoui64_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 188457)
+++ 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 188457)
+++ 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,26 +41,27 @@
                    size_t nwc, size_t len, mbstate_t *__restrict ps );
 }
 
-#if defined(_LIBCPP_MSVCRT)
+// FIXME: These functions are problematic and the versioning story
+// needs to be worked out if support should remain. Things to note:
+// * macros are less than ideal.
+// * Some are standard so conflict as newer base C libraries that libcxx
+// begin to support them itself. GNU and MS being examples.
+// * Some like snprintf map to versions that aren't quite equivalent.
+//   This causes as many problems as it solves so is questionable.
+#if (defined(_MSC_VER) && _MSC_VER < 1800) || (defined(__GNUC__) && __GNUC__ < 4)
+#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); }
+inline void _Exit( int status ) { _exit(status); }
+#endif
 
-#define _Exit _exit
+#if _MSC_VER && !__clang__ // clang supports these intrinsics.
 
-#ifndef __clang__ // MSVC-based Clang also defines _MSC_VER
-#include <intrin.h>
-
 _LIBCPP_ALWAYS_INLINE int __builtin_popcount(unsigned int x) {
    static const unsigned int m1 = 0x55555555; //binary: 0101...
    static const unsigned int m2 = 0x33333333; //binary: 00110011..
@@ -105,10 +117,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/support/win32/locale_win32.cpp
===================================================================
--- src/support/win32/locale_win32.cpp	(revision 188457)
+++ 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 );
Index: src/support/win32/support.cpp
===================================================================
--- src/support/win32/support.cpp	(revision 188457)
+++ src/support/win32/support.cpp	(working copy)
@@ -29,44 +29,43 @@
     va_list ap;
     va_start(ap, format);
     int result;
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    try {
-#endif
-        result = vasprintf(sptr, format, ap);
-#ifndef _LIBCPP_NO_EXCEPTIONS
-    } catch( ... ) {
-        va_end(ap);
-        throw;
-    }
-#endif
+    result = vasprintf(sptr, format, ap);
     va_end(ap);
     return result;
 }
 
-// Like sprintf, but when return value >= 0 it returns a pointer to a malloc'd string in *sptr.
+// Like sprintf, but when return value >= 0 it returns
+// a pointer to a malloc'd string in *sptr.
 // If return >= 0, use free to delete *sptr.
 int vasprintf( char **sptr, const char *__restrict format, va_list ap )
 {
     *sptr = NULL;
-    int count = _vsnprintf( NULL, 0, format, ap ); // Query the buffer size required.
-    if( count >= 0 ) {
-        std::unique_ptr<char, free_deleter> p( static_cast<char*>(malloc(count+1)) );
-        if ( ! p )
-            return -1;
-        if ( vsnprintf( p.get(), count+1, format, ap ) == count ) // We should have used exactly what was required.
-            *sptr = p.release();
-        else // Otherwise something is wrong, likely a bug in vsnprintf. If so free the memory and report the error.
-            return -1; // Pointer will get automaticlaly deleted.
-    }
-
+    // Query the buffer size required.
+    int result = _vsnprintf( NULL, 0, format, ap );
+    if (result < 0)
+        return result;
+    size_t count = result;
+    std::unique_ptr<char, free_deleter> p( static_cast<char*>(malloc(count+1)) );
+    if ( ! p )
+        return -1;
+    // If we haven't used exactly what was required, something is wrong.
+    // Maybe bug in vsnprintf. Report the error and return.
+    // The pointer will get automaticlaly deleted.
+    if ( vsnprintf( p.get(), count+1, format, ap ) != result )
+        return -1;
+    // All good. This is returning memory to the caller not freeing it.
+    *sptr = p.release();
     return count;
 }
 
-// Returns >= 0: the number of wide characters found in the multi byte sequence src (of src_size_bytes),
-// that fit in the buffer dst (of max_dest_chars elements size). The count returned excludes the null terminator.
-// When dst is NULL, no characters are copied and no "out" parameters are updated.
+// Returns >= 0: the number of wide characters found in the 
+// multi byte sequence src (of src_size_bytes), that fit in the buffer dst 
+// (of max_dest_chars elements size). The count returned excludes the
+// null terminator. When dst is NULL, no characters are copied 
+// and no "out" parameters are updated.
 // Returns (size_t) -1: an incomplete sequence encountered.
-// Leaves *src pointing the next character to convert or NULL if a null character was converted from *src.
+// Leaves *src pointing the next character to convert or NULL 
+// if a null character was converted from *src.
 size_t mbsnrtowcs( wchar_t *__restrict dst, const char **__restrict src,
                    size_t src_size_bytes, size_t max_dest_chars, mbstate_t *__restrict ps )
 {
@@ -112,10 +111,13 @@
 }
 
 // Converts max_source_chars from the wide character buffer pointer to by *src,
-// into the multi byte character sequence buffer stored at dst which must be dst_size_bytes bytes in size.
-// Returns >= 0: the number of bytes in the sequence sequence converted frome *src, excluding the null terminator.
+// into the multi byte character sequence buffer stored at dst which must be
+// dst_size_bytes bytes in size.
+// Returns >= 0: the number of bytes in the sequence sequence 
+// converted frome *src, excluding the null terminator.
 // Returns size_t(-1) if an error occurs, also sets errno.
-// If dst is NULL dst_size_bytes is ignored and no bytes are copied to dst and no "out" parameters are updated.
+// If dst is NULL dst_size_bytes is ignored and no bytes are copied to dst 
+// and no "out" parameters are updated.
 size_t wcsnrtombs( char *__restrict dst, const wchar_t **__restrict src,
                    size_t max_source_chars, size_t dst_size_bytes, mbstate_t *__restrict ps )
 {
@@ -138,7 +140,8 @@
             result = wcrtomb_s( &char_size, dst + dest_converted, dest_remaining, c, ps);
         else
             result = wcrtomb_s( &char_size, NULL, 0, c, ps);
-        // If result is zero there is no error and char_size contains the size of the multi-byte-sequence converted.
+        // If result is zero there is no error and char_size contains the 
+		// size of the multi-byte-sequence converted.
         // Otherwise result indicates an errno type error.
         if ( result == no_error ) {
             if ( c == L'\0' ) {
