Fix crash on Mac OS X, accessing stdout during static initialisation.

This commit is contained in:
Dair Grant 2013-06-30 15:33:38 +01:00
parent 7293c9785a
commit 06f3b505ec

View File

@ -126,19 +126,22 @@ namespace Catch {
void use( Colour::Code ) {} void use( Colour::Code ) {}
}; };
NoColourImpl noColourImpl; NoColourImpl noColourImpl;
static const bool shouldUseColour = shouldUseColourForPlatform() &&
!isDebuggerActive();
} }
Colour::Colour( Code _colourCode ){ use( _colourCode ); } Colour::Colour( Code _colourCode ){ use( _colourCode ); }
Colour::~Colour(){ use( None ); } Colour::~Colour(){ use( None ); }
void Colour::use( Code _colourCode ) { void Colour::use( Code _colourCode ) {
if (impl == NULL) {
impl = (shouldUseColourForPlatform() && !isDebuggerActive())
? static_cast<Detail::IColourImpl*>( &platformColourImpl )
: static_cast<Detail::IColourImpl*>( &noColourImpl );
}
impl->use( _colourCode ); impl->use( _colourCode );
} }
Detail::IColourImpl* Colour::impl = shouldUseColour Detail::IColourImpl* Colour::impl = NULL;
? static_cast<Detail::IColourImpl*>( &platformColourImpl )
: static_cast<Detail::IColourImpl*>( &noColourImpl );
} // end namespace Catch } // end namespace Catch