philsquared/Catch — Issue #72: Simple if/else without block scope {} does not compile
Author: colonelsammy
Created: 2012-02-20 16:09:31+00:00
State: open

Example:

#define CATCH_CONFIG_MAIN
#include "catch.hpp"
TEST_CASE("bad if statement", "")
{
size_t x = 0;

if( x )
REQUIRE(x > 0);
else
REQUIRE(x == 0);
}

You need to do something like putting a do{ } while(0) around the macro body of INTERNAL_CATCH_TEST....e.g:

#define INTERNAL_CATCH_TEST( expr, isNot, stopOnFailure, macroName ) \
do {INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( __FILE__, __LINE__, macroName, #expr, isNot )->*expr ), stopOnFailure ); \
if( Catch::isTrue( false ) ){ bool internal_catch_dummyResult = ( expr ); Catch::isTrue( internal_catch_dummyResult ); }} while (0)