Errors when compiling catch with Visual Studio 2008

102 Views Asked by At

Update: using catch 1.9.7 solved this problem.

I am just getting started with using catch and have been unable to get even a simple test project to compile. I am using Visual Studio 2008 and have catch.hpp v1.10.0 (single file version).

I created a simple test project following the catch tutorial. main.cpp is the only file and the code consists of:

#define CATCH_CONFIG_MAIN
#include "catch.hpp"

TEST_CASE("test case 1")
{
    REQUIRE(1==2);
}

I get the following errors when I compile:

c:\utilities\catch\catchtest\catchtest\catch.hpp(1333) : warning C4181: qualifier applied to reference type; ignored
c:\utilities\catch\catchtest\catchtest\catch.hpp(1838) : see reference to class template instantiation 'Catch::Internal::Evaluator<T1,T2,Op>' being compiled
with
[
    T1=const int &,
    T2=const int &,
    Op=IsEqualTo
]
c:\utilities\catch\catchtest\catchtest\catch.hpp(1836) : while compiling class template member function 'void Catch::BinaryExpression<LhsT,Op,RhsT>::endExpression(void) const'
with
[
    LhsT=const int &,
    Op=IsEqualTo,
    RhsT=const int &
]
c:\utilities\catch\catchtest\catchtest\main.cpp(8) : see reference to class template instantiation 'Catch::BinaryExpression<LhsT,Op,RhsT>' being compiled
with
[
    LhsT=const int &,
    Op=IsEqualTo,
    RhsT=const int &
]
c:\utilities\catch\catchtest\catchtest\catch.hpp(1333) : error C2529: 'lhs' : reference to reference is illegal
c:\utilities\catch\catchtest\catchtest\catch.hpp(1333) : warning C4181: qualifier applied to reference type; ignored
c:\utilities\catch\catchtest\catchtest\catch.hpp(1333) : error C2529: 'rhs' : reference to reference is illegal
c:\utilities\catch\catchtest\catchtest\catch.hpp(1838) : error C2664: 'Catch::Internal::Evaluator<T1,T2,Op>::evaluate' : cannot convert parameter 1 from 'const int' to 'const int &(&)'
with
[
    T1=const int &,
    T2=const int &,
    Op=IsEqualTo
]
c:\utilities\catch\catchtest\catchtest\catch.hpp(1839) : error C2228: left of '.endExpression' must have class/struct/union

Any assistance would be much appreciated. I haven't been able to find anything in the catch documentation or online and am eager to get started with it.

2

There are 2 best solutions below

0
On

The latest master of Catch is for modern C++ compiler and the Visual Studio 2008 compiler is pretty old now. There's some switches you can use to downgrade some of the features:

https://github.com/philsquared/Catch/blob/master/docs/configuration.md

Try it with 'CATCH_CONFIG_NO_CPP11' defined before #include'ing catch.

0
On

For future reference: support for MSVC 9 was broken by this commit and reverting b6e7c9bd7a160c07c5de894292022687895c17a3 (done on top of it) and then this one is sufficient to fix the problem.