From 1f97d4d318c577b91bd6e95f2518a3e48c9758b4 Mon Sep 17 00:00:00 2001 From: Andrew Foster Date: Mon, 10 Oct 2016 11:34:19 +0100 Subject: [PATCH] Fixed std::distance compile error with Oracle Solaris Studio 12.1 Building Catch with Oracle Solaris Studio 12.1 generates an error when calling std::distance due to the toolchains non-compliant STL implementation. This implementation returns its result via an output parameter rather than a return value. --- include/internal/catch_compiler_capabilities.h | 10 ++++++++++ include/reporters/catch_reporter_compact.hpp | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/include/internal/catch_compiler_capabilities.h b/include/internal/catch_compiler_capabilities.h index 5af1e76a..3e64b202 100644 --- a/include/internal/catch_compiler_capabilities.h +++ b/include/internal/catch_compiler_capabilities.h @@ -119,6 +119,16 @@ #endif // _MSC_VER +//////////////////////////////////////////////////////////////////////////////// +// Oracle Solaris Studio +#ifdef __SUNPRO_CC + +# if __SUNPRO_CC == 0x5100 // Oracle Solaris Studio version 12.1 +# define CATCH_INTERNAL_SUNPRO_CC_NON_COMPLIANT_STL +# endif + +#endif // __SUNPRO_CC + //////////////////////////////////////////////////////////////////////////////// // Use variadic macros if the compiler supports them diff --git a/include/reporters/catch_reporter_compact.hpp b/include/reporters/catch_reporter_compact.hpp index a5a17297..2541f5d7 100644 --- a/include/reporters/catch_reporter_compact.hpp +++ b/include/reporters/catch_reporter_compact.hpp @@ -218,7 +218,12 @@ namespace Catch { // using messages.end() directly yields compilation error: std::vector::const_iterator itEnd = messages.end(); +# ifdef CATCH_INTERNAL_SUNPRO_CC_NON_COMPLIANT_STL + std::size_t N; + std::distance( itMessage, itEnd, N ); +# else const std::size_t N = static_cast( std::distance( itMessage, itEnd ) ); +# endif // CATCH_INTERNAL_SUNPRO_CC_NON_COMPLIANT_STL { Colour colourGuard( colour );