Boost logo

Boost Testing :

Subject: [Boost-testing] Regression with -Woverloaded-virtual in unit_test_log_t
From: Ben Wiederhake (ben.wiederhake_at_[hidden])
Date: 2015-08-26 15:48:43


Hello,

while trying to compile my code with "-Woverloaded-virtual -Werror", I
found a shortcoming, possibly even a bug.

In 1.59.0 (and, as far as I can see in git, all following versions),
there are the following declarations/definitions:

     class test_observer /* boost/test/tree/observer.hpp:40 */
     virtual void test_unit_skipped( test_unit const& tu, const_string)
        { test_unit_skipped( tu ); }
     virtual void test_unit_skipped( test_unit const& )
        {} ///< backward compartibility

     class unit_test_log_t /* boost/test/unit_test_log.hpp:97 */
     virtual void test_unit_skipped( test_unit const&, const_string );
     /* Actually uses the message in the implementation */
     /* Does not override Test_unit_skipped( test_unit const& ) */

The problem with this code is that code like the following simply will
not work:

     unit_test_log_t& foobar;
     test_unit const& tu;
     foobar.test_unit_skipped( tu ); // <-- Error!

g++ would say "candidate expects 2 arguments, 1 provided". clang++ is a
tad more helpful, and would say: "too few arguments to function call,
expected 2, have 1; did you mean 'test_observer::test_unit_skipped'?"
In case you're unfamiliar with that behaviour, see this specific answer:
http://stackoverflow.com/a/6035884/3070326
(Error messages are from a different compilation, but should be the same.)

I hope I have now established that -Woverloaded-virtual "has a point".

I don't fully understand why unit_test_log_t doesn't override the
other signature, too; but it should be easily possible to override
it with something like:

     test_unit_skipped( tu, "<No message>" );

However, I do not yet fully understand the context of unit_test_log_t,
so maybe such a call cannot occur. That's why I'm unable to make a
patch from that idea (in contrast to the 'compartibility' typo: see #84
on github).

At the very least, this issue is annoying for people who use Boost.Test
and try to compile with -Woverloaded-virtual. Note that Boost.Test
1.58.0 did not exhibit this issue (I upgraded only recently), so I
felt free to put "regression" in the subject.

With regards,
Ben Wiederhake


Boost-testing list run by mbergal at meta-comm.com