Added generator copy ctor to fix bug when NRVO is not used. Some exception handling improvements, too

This commit is contained in:
Phil Nash 2011-02-23 09:06:05 +00:00
parent 6bfc1b6016
commit 331188f6b3
4 changed files with 48 additions and 7 deletions

View File

@ -41,6 +41,7 @@
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories="\\psf\Host\TwoBlueCubes\Dev\GitHub\Catch"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true" MinimalRebuild="true"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
@ -202,10 +203,18 @@
RelativePath="..\..\..\ExceptionTests.cpp" RelativePath="..\..\..\ExceptionTests.cpp"
> >
</File> </File>
<File
RelativePath="..\..\..\GeneratorTests.cpp"
>
</File>
<File <File
RelativePath="..\..\..\MessageTests.cpp" RelativePath="..\..\..\MessageTests.cpp"
> >
</File> </File>
<File
RelativePath="..\..\..\MiscTests.cpp"
>
</File>
<File <File
RelativePath="..\..\..\TrickyTests.cpp" RelativePath="..\..\..\TrickyTests.cpp"
> >

View File

@ -17,6 +17,15 @@
#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
#define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) #define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
#ifdef __GNUC__
#define ATTRIBUTE_NORETURN __attribute__ ((noreturn))
#else
#define ATTRIBUTE_NORETURN
#endif
#include <sstream>
#include <stdexcept>
namespace Catch namespace Catch
{ {
class NonCopyable class NonCopyable
@ -54,12 +63,16 @@ namespace Catch
} }
} }
ATTRIBUTE_NORETURN
inline void throwLogicError( const std::string& message, const std::string& file, long line )
{
std::ostringstream oss;
oss << "Internal Catch error: '" << message << "' at: " << file << "(" << line << ")";
throw std::logic_error( oss.str() );
}
} }
#ifdef __GNUC__
#define ATTRIBUTE_NORETURN __attribute__ ((noreturn)) #define CATCH_INTERNAL_ERROR( msg ) throwLogicError( msg, __FILE__, __LINE__ );
#else
#define ATTRIBUTE_NORETURN
#endif
#endif // TWOBLUECUBES_CATCH_COMMON_H_INCLUDED #endif // TWOBLUECUBES_CATCH_COMMON_H_INCLUDED

View File

@ -129,6 +129,15 @@ public:
{ {
} }
///////////////////////////////////////////////////////////////////////////
// *** Move semantics, similar to auto_ptr ***
CompositeGenerator( CompositeGenerator& other )
: m_fileInfo( other.m_fileInfo ),
m_totalSize( 0 )
{
move( other );
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
CompositeGenerator& setFileInfo CompositeGenerator& setFileInfo
( (
@ -164,7 +173,7 @@ public:
} }
index += generator->size(); index += generator->size();
} }
throw "this should never happen!"; CATCH_INTERNAL_ERROR( "Indexed past end of generated range" );
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////

View File

@ -596,6 +596,16 @@ namespace Catch
acceptMessage( ex.what() ); acceptMessage( ex.what() );
acceptResult( ResultWas::ThrewException ); acceptResult( ResultWas::ThrewException );
} }
catch( std::string& msg )
{
acceptMessage( msg );
acceptResult( ResultWas::ThrewException );
}
catch( const char* msg )
{
acceptMessage( msg );
acceptResult( ResultWas::ThrewException );
}
catch(...) catch(...)
{ {
acceptMessage( "unknown exception" ); acceptMessage( "unknown exception" );