Closed
Description
Compiling:
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
TEST_CASE( "Syntax error with VC12", "" )
{
for ( auto x : { 1 , 2, 3 } )
REQUIRE( x < 3.14 );
}
yields:
range-for-catch.cpp(7) : error C2059: syntax error : '}'
This VC12 behaviour is reported as do-while loop within range-based-for fails to compile.
See also Range-for, with try/catch statement, not compiling.
Workaround for users of Catch:
TEST_CASE( "Enclose in block to compile with VC12", "" )
{
for ( auto x : { 1 , 2, 3 } )
{
REQUIRE( x < 3.14 );
}
}
With Catch REQUIRE
expanded and simplified this boils down to:
void fail()
{
for ( auto x: { 1, 2, 3 } )
do
{
try { }
catch( std::exception const & ) {}
}
while ( false );
}
Workaround is to enclose do {} while();
in block:
void pass()
{
for ( auto x: { 1, 2, 3 } )
{
do
{
try { }
catch( std::exception const & ) {}
}
while ( false );
}
}
This changes REQUIRE()
from an iteration statement into a compound statement. What consequences may this have, if any?
Metadata
Assignees
Labels
No labels