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.
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 )
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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 http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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);"
http://www.noveltheory.com/TechPapers/while.htm
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 )
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
Ok - I've closed the issue. May try working around it with a wrapper macro.
Thanks,
Mike
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
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center