#55 Fix compiler warning on VS 2005

Mike Talbot

I get a load of "warning C4127: conditional expression is constant" warnings in my project when using the CPPUNIT_ASSERT_THROW macro with compiler warning level set to /W4. Attached patch fixes these.


  • Niels Dekker

    Niels Dekker - 2008-11-01

    Mike, your patch would remove do-while(false) from CPPUNIT_ASSERT_THROW_MESSAGE and CPPUNIT_ASSERT_NO_THROW_MESSAGE. Are you sure that's a good idea?

    Please note that "do {} while(false)" is a known trick, forcing the caller of the macro to always put a semi-colon (;) at the end of the macro call.

    See also:
    James M. Curran - "Fun With do {} while(FALSE);"

  • Mike Talbot

    Mike Talbot - 2008-11-03

    Interesting article - I guess it could potentially break existing code (e.g. with the semi-colon after an if-else block, as shown in the article). So it should probably be left as the original "do {} while {false}".

    Shame there isn't another way to work around the compiler warnings (we like to complie with the highest warning level to try to keep our code clean) - normally putting #pramgas around 3rd party #includes handles issues with other libraries, but not with macros (unless we define a wrapper macro with #pragams around the CPPUNIT macro... but that's just getting silly :-O )

  • Niels Dekker

    Niels Dekker - 2008-11-03

    I agree that it's a pity that this wonderful do-while(false) trick gets us those compiler warnings. Unfortunately I don't know how to solve it, other that by #pragma warning(disable:4127), or Microsoft compiler option /wd4127.

    Are you sure you can put a #pragma inside a wrapper macro (however silly)? I'm afraid it doesn't work either.

    If you agree that your patch doesn't do the right thing, can you please remove it from Tracker?

    Kind regards, Niels

  • Mike Talbot

    Mike Talbot - 2008-11-03

    Ok - I've closed the issue. May try working around it with a wrapper macro.

  • Mike Talbot

    Mike Talbot - 2008-11-03
    • status: open --> closed-rejected
  • Niels Dekker

    Niels Dekker - 2008-11-03

    Thanks for closing the issue, Mike. Please let me know if you've found a better way to avoid those warnings... or just submit a new patch!
    Niels Dekker
    Scientific programmer at LKEB, Leiden University Medical Center


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks