Date: prev next · Thread: first prev next last
2017 Archives by date, by thread · List index


In include/cppunit/TestAssert.h, CPPUNIT_ASSERT is effectively defined as

#define CPPUNIT_ASSERT(condition) CppUnit::Asserter::failIf(!(condition), ...)

So if the expression 'condition' is such that an overloaded operator ! applies, then that will be used instead of the expected(?) built-in !.

Should this be considered a bug or a feature?  I am somewhat undecided.

On the one hand, CPPUNIT_ASSERT is used to assert that something is "true". That it uses double negation (failIf, !) for that should probably be considered an implementation detail. And "arbitrary" overloaded operator ! shouldn't get into the way of that.

On the other hand, changing this like

#define CPPUNIT_ASSERT(condition) CppUnit::Asserter::failIf(!(bool(condition)), ...)

could cause existing code to fail. Either fail to compile (if the relevant type cannot be converted to bool) or, worse, cause the semantics of the test to change (if the original code relied on a specific overloaded operator ! being called).

(I came across this in LO, where cppcanvas/qa/unit/test.cxx contains

CPPUNIT_ASSERT( aBitmapEx.GetAlpha() );

and the condition is of type AlphaMask that has an overloaded operator ! -- but no conversion to bool, which is probably a design bug of its own.)

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.