Attached is a patch for stdlib library.

  ChangeLog:
  * _num_put.cc (__rw_iter_failed): Removed const to resolve
  ambiguity on MSVC 7.0
  * _select.h [_RWSTD_NO_CLASS_PARTIAL_SPEC]: Added __rw_is_same
  for compilers which not support the partial template specialization
  * sstream.cc (basic_stringbuf<>::str): Added check before deallocate
  the old buffer
  * file.cpp: Declare fileno() only if it not declared in CRT header,
  but presend in libc
  * exception.cpp [_MSC_VER]: #undefined _RWSTD_NO_VSNPRINTF after
  #define vsnprintf _vsnprintf
  (__rw_free_what_buf): New function to free buffer for what message
  (__rw_vfmtwhat): Used __rw_free_what_buf to free buffer
  (__rw_throw_exception [_RWSTD_NO_EXCEPTIONS]): Used __rw_free_what_buf
  to free buffer
  (__rw_throw_exception [!_RWSTD_NO_EXCEPTIONS]): Don't free buffer
  before return from function
  (__rw_throw): Used __rw_free_what_buf to free buffer
  (~__rw_exception): The same

Farid.
Index: include/loc/_num_put.cc
===================================================================
--- include/loc/_num_put.cc     (revision 450907)
+++ include/loc/_num_put.cc     (working copy)
@@ -42,13 +42,15 @@
 inline bool
 __rw_iter_failed (const _OutputIter&) { return false; }
 
+// const commented to resolve ambiguity on MSVC 7.0:
+// error C2667: '__rw_iter_failed' : none of 2 overloads have a best conversion
 template <class _CharT, class _Traits>
 inline bool
-__rw_iter_failed (const _STD::ostreambuf_iterator<_CharT, _Traits> &__it)
+__rw_iter_failed (/*const */_STD::ostreambuf_iterator<_CharT, _Traits> &__it)
 {
     return __it.failed ();
 }
-
+
 }   // namespace __rw
 
 
Index: include/rw/_select.h
===================================================================
--- include/rw/_select.h        (revision 450907)
+++ include/rw/_select.h        (working copy)
@@ -90,6 +90,8 @@
 #endif
 
 
+#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
+
 template <class _TypeT, class _TypeU>
 struct __rw_is_same
 {
@@ -97,8 +99,6 @@
     enum { _C_val };
 };
 
-#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
-
 template <class _TypeT>
 struct __rw_is_same<_TypeT, _TypeT>
 {
@@ -108,23 +108,35 @@
 
 #else   // if defined (_RWSTD_NO_CLASS_PARTIAL_SPEC)
 
-_RWSTD_SPECIALIZED_CLASS
-struct __rw_is_same<char, char>
+template <bool flag>
+struct __rw_bool_t
 {
-    typedef __rw_true_t _C_type;
-    enum { _C_val = 1 };
+    typedef __rw_false_t _C_type;
 };
 
-#  ifndef _RWSTD_NO_WCHAR_T
-
 _RWSTD_SPECIALIZED_CLASS
-struct __rw_is_same<wchar_t, wchar_t>
+struct __rw_bool_t<true>
 {
     typedef __rw_true_t _C_type;
-    enum { _C_val = 1 };
 };
 
-#  endif   // _RWSTD_NO_WCHAR_T
+template <class _TypeT, class _TypeU>
+struct __rw_is_same
+{
+    struct yes {};
+    struct no { yes no_ [2]; };
+    template <class T>
+    struct Type {};
+
+    static yes test (Type<_TypeT>, Type<_TypeT>);
+    static no test (...);
+
+    enum { _C_val = sizeof (test (Type<_TypeT> (),
+                                  Type<_TypeU> ())) == sizeof (yes) };
+
+    typedef _TYPENAME __rw_bool_t<_C_val>::_C_type _C_type;
+};
+
 #endif   // _RWSTD_NO_CLASS_PARTIAL_SPEC
 
 
Index: include/sstream.cc
===================================================================
--- include/sstream.cc  (revision 450907)
+++ include/sstream.cc  (working copy)
@@ -135,11 +135,13 @@
         // copy the provided string to buffer
         traits_type::copy (__buf, __s, __slen);
 
-        if (this->_C_buffer && this->_C_own_buf ())
-            __alloc.deallocate (this->_C_buffer, this->_C_bufsize);
+        if (this->_C_buffer != __buf) {
+            if (this->_C_buffer && this->_C_own_buf ())
+                __alloc.deallocate (this->_C_buffer, this->_C_bufsize);
 
-        this->_C_buffer  = __buf;
-        this->_C_bufsize = __bufsize;
+            this->_C_buffer  = __buf;
+            this->_C_bufsize = __bufsize;
+        }
     }
 
     if (this->_C_is_in ())
Index: src/exception.cpp
===================================================================
--- src/exception.cpp   (revision 450828)
+++ src/exception.cpp   (working copy)
@@ -71,6 +71,7 @@
 #ifdef _MSC_VER
    // MSVC's libc prepends an underscore
 #  define vsnprintf   _vsnprintf
+#  undef  _RWSTD_NO_VSNPRINTF
 #endif
 
 #if defined (_RWSTD_NO_VSNPRINTF) && !defined (_RWSTD_NO_VSNPRINTF_IN_LIBC)
@@ -436,6 +437,13 @@
 static _RWSTD_THREAD int
 __rw_what_refcnt;
 
+static void __rw_free_what_buf (char* buf)
+{
+    if (buf == __rw_what_buf)
+        _RWSTD_THREAD_PREDECREMENT (__rw_what_refcnt, false);
+    else
+        delete[] buf;
+}
 
 // allocate a char array and format it sprintf-style
 // caller responsible for calling delete[] on returned pointer
@@ -545,14 +553,9 @@
         if (bufsize)
             return 0;
 
-        if (buf == __rw_what_buf) {
-            _RWSTD_THREAD_PREDECREMENT (__rw_what_refcnt, false);
-        }
-        else {
-            delete[] buf;
-        }
-        buf = new char [size];
+        __rw_free_what_buf (buf);
 
+        buf = new char [size];
     }
 
     return buf;
@@ -739,13 +742,11 @@
             _STD::runtime_error ()._C_assign (what, 0);
     }
 
-    delete[] what;
-
 #else   // if defined (_RWSTD_NO_EXCEPTIONS)
 
     if (what) {
         fprintf (stderr,"Exception: %s.\n", what);
-        delete[] what;
+        __rw_free_what_buf (what);
     }
     else {
         const char *__str;
@@ -826,7 +827,7 @@
         __rw_throw_proc (id, what);
 
         // if throw_proc returns, delete allocated what string
-        delete[] what;
+        __rw_free_what_buf (what);
     }
 }
 
@@ -865,12 +866,7 @@
 // outlined to avoid functional compatibility issues
 /* virtual */ __rw_exception::~__rw_exception () _THROWS (())
 {
-    if (_C_what == __rw_what_buf) {
-        _RWSTD_THREAD_PREDECREMENT (__rw_what_refcnt, false);
-    }
-    else {
-        delete[] _C_what;
-    }
+    __rw_free_what_buf (_C_what);
 
 #ifdef _C_dummy_what
     // zero out dummy member of the base exception class
Index: src/file.cpp
===================================================================
--- src/file.cpp        (revision 450828)
+++ src/file.cpp        (working copy)
@@ -2,7 +2,7 @@
  *
  * support.cpp - definition of support functions and objects
  *
- * $Id: //stdlib/dev/source/stdlib/file.cpp#3 $
+ * $Id$
  *
  ***************************************************************************
  *
@@ -78,14 +78,20 @@
 #endif   // _RWSTD_NO_MKSTEMP[_IN_LIBC]
 
 
+#if defined (_RWSTD_NO_FILENO) && !defined (_RWSTD_NO_FILENO_IN_LIBC)
+
 // declare fileno in case it's not declared (for strict ANSI conformance)
 extern "C" {
 
 _RWSTD_DLLIMPORT int (fileno)(FILE*) _LIBC_THROWS ();
 
+#  undef _RWSTD_NO_FILENO
+
 }   // extern "C"
 
+#endif   // _RWSTD_NO_FILENO && !_RWSTD_NO_FILENO_IN_LIBC
 
+
 _RWSTD_NAMESPACE (__rw) {
 
 

Reply via email to