[Cppunit-devel] MSVC++ warning
Brought to you by:
blep
|
From: Summerwill, B. <BSu...@eu...> - 2002-01-24 11:41:53
|
I'm getting an MSVC++ level 4 warning everywhere I use the OStringStream
class. Here's one example ...
CppUnitExtensions\XMLResults.cpp(67) : warning C4701: local variable
'Stream' may be used without having been initialized
static std::string GetExceptionLineNumber(CppUnit::Exception* pException)
{
const long StoredValue = pException->lineNumber();
if (CppUnit::Exception::UNKNOWNLINENUMBER == StoredValue)
{
return "Unknown";
}
CppUnit::OStringStream Stream; <== This is the line the
warning refers to
Stream << StoredValue;
return Stream.str();
}
I can only assume it's due to some compiler confusion about the typedef'd
std::ostringstream constructor. It's a one-liner to fix (see below). I
would imagine this to be a fairly safe change (unless client code is making
use of the non-default constructor). It would be similar to the
std::ostrstream subclass in the same file.
In Portability.h
----------------
#if CPPUNIT_HAVE_SSTREAM
# include <sstream>
namespace CppUnit {
- typedef std::ostringstream OStringStream;
+ class OStringStream : public std::ostringstream {};
}
#else
#if CPPUNIT_HAVE_CLASS_STRSTREAM
Cheers,
Bob Summerwill
|