From 059dbd8c75146ce44e5e39bcf65a80efc5a918e5 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Tue, 23 Sep 2014 03:36:51 +0200 Subject: [PATCH] fix and finish the diagnostics helper there was still a subtle bug in this helper. testing your own test fixture is sometimes a good idea ;-) --- src/lib/test/test-helper.hpp | 14 +++++++--- tests/40core.tests | 27 +++++++++++++++++++ .../test/test-helper-variadic-test.cpp | 25 +++++++++-------- 3 files changed, 50 insertions(+), 16 deletions(-) diff --git a/src/lib/test/test-helper.hpp b/src/lib/test/test-helper.hpp index 3d0332c3f..425fc8429 100644 --- a/src/lib/test/test-helper.hpp +++ b/src/lib/test/test-helper.hpp @@ -112,7 +112,14 @@ namespace test{ : "VAL"; } - /** helper for investigating a variadic argument pack */ + /** helper for investigating a variadic argument pack + * @warning always spell out the template arguments explicitly + * when invoking this diagnostics, e.g. \c showVariadicTypes(args...) + * otherwise the template argument matching for functions might mess up the + * kind of reference you'll see in the diagnostics. + * @see test-helper-variadic-test.cpp + */ + template inline string showVariadicTypes () { @@ -120,7 +127,7 @@ namespace test{ } template - string + inline string showVariadicTypes (X const& x, XS const&... xs) { return " :---#" @@ -129,12 +136,13 @@ namespace test{ + " " + showRefKind() + " Address* " + boost::lexical_cast(&x) + "\n" - + showVariadicTypes (xs...); + + showVariadicTypes (xs...); } + /** create a random but not insane Time value */ inline lib::time::Time randTime () diff --git a/tests/40core.tests b/tests/40core.tests index e0a71338c..e70b53f74 100644 --- a/tests/40core.tests +++ b/tests/40core.tests @@ -822,6 +822,33 @@ out: sizeof.+lib.+test.+test.+Wrmrmpft.+Murpf.+ = 1 END +TEST "Variadic template diagnostics" TestHelperVariadic_test < Testgroup=ALL diff --git a/tests/library/test/test-helper-variadic-test.cpp b/tests/library/test/test-helper-variadic-test.cpp index d171dcf4c..2997bb688 100644 --- a/tests/library/test/test-helper-variadic-test.cpp +++ b/tests/library/test/test-helper-variadic-test.cpp @@ -23,21 +23,15 @@ #include "lib/test/run.hpp" #include "lib/test/test-helper.hpp" -//#include "lib/util.hpp" -//#include #include #include #include #include -//#include -//using boost::lexical_cast; -//using util::contains; using std::string; using std::cout; -//using std::endl; namespace lib { @@ -65,7 +59,7 @@ namespace test{ string s_; public: - Impl(string ss ="IMP") : s_(ss) { } + Impl(string ss ="ZOMG") : s_(ss) { } }; @@ -106,28 +100,33 @@ namespace test{ { double d = makeRvalue(); double& dr = d; - + Impl obj; Interface const& ref = obj; - + cout << "--no-arg--\n" << showVariadicTypes() <<"\n"; cout << "--value--\n" << showVariadicTypes(d) <<"\n"; cout << "--reference--\n" << showVariadicTypes(d) <<"\n"; cout << "--move--\n" << showVariadicTypes(d) <<"\n"; - forwardFunction("two values", "foo", 42L); - forwardFunction("matched", d,dr,std::move(dr)); + forwardFunction("two values", "foo", 42L); // passed as REF, MOV + forwardFunction("matched", d,dr,std::move(dr)); // passed as REF, REF, MOV forwardFunction("baseclass", ref); } + /** this dummy simulates a typical variadic call + * which takes all arguments as '&&' for the purpose of "perfect forwarding" + */ template void - forwardFunction (string id, ARGS const&... args) + forwardFunction (string id, ARGS&&... args) { + // in reality here you'd invoke some factory((args)...) + // cout << "--"<(args...) + << showVariadicTypes(args...) << "\n" ; }