Variadic Macros

138 views
Skip to first unread message

Phil Nash

unread,
Mar 16, 2013, 4:29:38 PM3/16/13
to catch...@googlegroups.com
I've checked in initial support for variadic macros to the integration branch.
This allows you to specify TEST_CASES with 0, 1 or 3 arguments and SECTIONS with 1 or 2. This should get rid of a lot of redundant ""s.

Variadic macros are standard in C++11 and C99 but many compilers (including gcc, clang and VC++) supported them in mostly compatible ways before that.

I have attempted to detect compiler support and conditionally enable variadic macros (falling back to the non variadic forms otherwise). The detection code is loosely based on the boost variadic macro detection code.
I've tesed this with gcc, clang and VC++10. I've not tested it with any compilers that don't have the required support.
If anyone has access to any of these other compilers I'd really appreciate if you could give it a try and let me know what happens (esp. failing to compiler due to lack of support - but also disabling support where it should be).

TIA.

Martin Moene

unread,
Mar 17, 2013, 7:06:01 AM3/17/13
to catch...@googlegroups.com
Given the compiler version test of
#if ( defined _MSC_VER && _MSC_VER >= 1400 && !defined __EDGE__) || \
...
    #define CATCH_CONFIG_VARIADIC_MACROS
it is no surprise that VC6 has no problem whatsoever with it (that is the VC6 port of CATCH).

Phil Nash

unread,
Mar 17, 2013, 7:35:36 AM3/17/13
to catch...@googlegroups.com
That's what I would expect - but isn't verifying expectations what testing is all about? :-D
Thanks for confirming that.
I believe 1400 corresponds to VS2005, which I believe was also the first version that supported variadic macros.

Martin Moene

unread,
Mar 17, 2013, 7:39:03 AM3/17/13
to catch...@googlegroups.com
I'll see if I can check VS2005/VC8 at work.

Martin Moene

unread,
Mar 18, 2013, 5:07:26 AM3/18/13
to catch...@googlegroups.com
Compiling with VC8 (VS2005) yields:

prompt>compile-variadic.bat
catch_self_test.cpp
TestMain.cpp
ApproxTests.cpp
ClassTests.cpp
ConditionTests.cpp
ExceptionTests.cpp
GeneratorTests.cpp
MessageTests.cpp
MiscTests.cpp
TrickyTests.cpp
VariadicMacrosTests.cpp
../../SelfTest/VariadicMacrosTests.cpp(12) : error C2143: syntax error : missing ')' before 'Catch::NameAndDesc'
../../SelfTest/VariadicMacrosTests.cpp(12) : error C2661: 'Catch::AutoReg::AutoReg' : no overloaded function takes 2 arguments
../../SelfTest/VariadicMacrosTests.cpp(12) : error C2059: syntax error : ')'
Generating Code...

With compile-variadic.bat:

cl -nologo -W3 -EHsc -GR -MD -I../../../include -FeTestCatch.exe  ../../SelfTest/catch_self_test.cpp ../../SelfTest/TestMain.cpp ../../SelfTest/ApproxTests.cpp ../../SelfTest/ClassTests.cpp ../../SelfTest/ConditionTests.cpp ../../SelfTest/ExceptionTests.cpp ../../SelfTest/GeneratorTests.cpp ../../SelfTest/MessageTests.cpp ../../SelfTest/MiscTests.cpp ../../SelfTest/TrickyTests.cpp  ../../SelfTest/VariadicMacrosTests.cpp  &&  TestCatch

Compiling without
VariadicMacrosTests.cpp succeeds, but crashes at runtime with:

TestCatch.exe - Application Error
The exception unknown software exception (0xc00000d) occurred in the application at location 0x78138aa0.
Click etc. ...

Running with -s, the last output is:

../../SelfTest/TestMain.cpp(282)::
PASSED:
  CHECK( config.allowThrows == false )
with expansion:
  false == false

Will see under VS2005 debugger...

Martin Moene

unread,
Mar 18, 2013, 6:40:30 AM3/18/13
to catch...@googlegroups.com
So VC8 has a problem at catch_test_registry(79):

    #define INTERNAL_CATCH_TESTCASE( ... ) \
        static void INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ )(); \
        namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME(  TestCaseFunction_catch_internal_ ), CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); }\
        static void INTERNAL_CATCH_UNIQUE_NAME(  TestCaseFunction_catch_internal_ )()


Phil Nash

unread,
Mar 18, 2013, 1:01:18 PM3/18/13
to catch...@googlegroups.com
Thanks for running those tests, Martin.
Looks like I'll need to be more careful with VC8. I should probably change the _MSC_VER check to exclude it from variadic macro support, for now.
Reply all
Reply to author
Forward
0 new messages