catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Revert "use sizeof(expr) for unevaluated syntax check"
- Commit
15816c5760cd6752d9d74759773044c638096422- Author
- Martin Hořeňovský ·
- Parents
02a69b449f59
Changes
include/internal/catch_capture.hpp | 3 ++- include/internal/catch_common.h | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp index eaf3074e..5d6a97ae 100644 --- a/include/internal/catch_capture.hpp +++ b/include/internal/catch_capture.hpp @@ -40,7 +40,8 @@ __catchResult.useActiveException( resultDisposition ); \ } \ INTERNAL_CATCH_REACT( __catchResult ) \ - } while( Catch::alwaysFalse( sizeof(expr) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look + } while( Catch::isTrue( false && static_cast<bool>( !!(expr) ) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look + // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&. /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_IF( expr, resultDisposition, macroName ) \ diff --git a/include/internal/catch_common.h b/include/internal/catch_common.h index 8d1a86a0..43f46a98 100644 --- a/include/internal/catch_common.h +++ b/include/internal/catch_common.h @@ -119,8 +119,9 @@ namespace Catch { std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); // This is just here to avoid compiler warnings with macro constants and boolean literals - inline bool alwaysTrue( std::size_t = 0 ) { return true; } - inline bool alwaysFalse( std::size_t = 0 ) { return false; } + inline bool isTrue( bool value ){ return value; } + inline bool alwaysTrue() { return true; } + inline bool alwaysFalse() { return false; } void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo );