diff --git a/research/try.cpp b/research/try.cpp index 9d2805acf..8f8108be1 100644 --- a/research/try.cpp +++ b/research/try.cpp @@ -39,11 +39,14 @@ // 03/18 - Dependency Injection / Singleton initialisation / double checked locking // 04/18 - investigate construction of static template members // 08/18 - Segfault when compiling some regular expressions for EventLog search +// 10/18 - investigate insidious reinterpret cast /** @file try.cpp - * Heisenbug hunt: random crashes in BusTerm_test, seemingly emerging from regular expression compilation. - * Not able to reproduce the crash, unfortunately. //////////////////////////////////////////////////////////TICKET #1158 + * Document an insidious wild cast, caused by the syntax `Type(arg)`. + * I was under the wrong assumption this would be handled equivalent to a constructor invocation. + * Seemingly it is rather handled as a C-style cast, i.e. equivalent to `(Type)arg`. + * @see [Question on Stackoverflow](https://stackoverflow.com/q/52782967/444796) */ typedef unsigned int uint; @@ -52,12 +55,10 @@ typedef unsigned int uint; #include "lib/test/test-helper.hpp" #include "lib/util.hpp" -#include #include -#include using std::string; -using VecS = std::vector; +using util::isSameObject; @@ -69,25 +70,32 @@ using VecS = std::vector; +class Wau + { + int i = -1; + }; + +class Miau + { + public: + uint u = 1; + }; + + + + + int main (int, char**) { - VecS rexs{{"after.+_ATTRIBS_.+ins.+1 of 62 ≺293.gen029≻.+mut.+1 of 62 ≺293.gen029≻.+ins.+borgID.+293.+emu.+1 of 62 ≺293.gen029≻" - ,"after.+_ATTRIBS_.+ins.+1 of 64 ≺251.gen019≻.+mut.+1 of 64 ≺251.gen019≻.+ins.+borgID.+251.+emu.+1 of 64 ≺251.gen019≻" - ,"after.+_ATTRIBS_.+ins.+1 of 8 ≺203.gen036≻.+mut.+1 of 8 ≺203.gen036≻.+ins.+borgID.+203.+emu.+1 of 8 ≺203.gen036≻" - ,"after.+?_ATTRIBS_.+?ins.+?53 of 57 ≺358.gen010≻.+?mut.+?53 of 57 ≺358.gen010≻.+?ins.+?borgID.+?358.+?emu.+?53 of 57 ≺358.gen010≻" - ,"after.+?_ATTRIBS_.+?ins.+?53 of 63 ≺178.gen028≻.+?mut.+?53 of 63 ≺178.gen028≻.+?ins.+?borgID.+?178.+?emu.+?53 of 63 ≺178.gen028≻" - ,"after.+?_ATTRIBS_.+?ins.+?53 of 59 ≺498.gen038≻.+?mut.+?53 of 59 ≺498.gen038≻.+?ins.+?borgID.+?498.+?emu.+?53 of 59 ≺498.gen038≻" - ,"after.+?_ATTRIBS_.+?ins.+?53 of 60 ≺223.gen003≻.+?mut.+?53 of 60 ≺223.gen003≻.+?ins.+?borgID.+?223.+?emu.+?53 of 60 ≺223.gen003≻" - ,"after.+?_ATTRIBS_.+?ins.+?53 of 78 ≺121.gen015≻.+?mut.+?53 of 78 ≺121.gen015≻.+?ins.+?borgID.+?121.+?emu.+?53 of 78 ≺121.gen015≻" - }}; - for (auto const& str : rexs) - { - auto rex = std::regex{str}; - SHOW_EXPR (std::regex_search(str, rex)); - } + Wau wau; + using ID = Miau &; + ID wuff = ID(wau); + cout << "Miau=" << wuff.u + << " ref to same object: " << isSameObject (wau, wuff) + << endl; cout << "\n.gulp.\n"; diff --git a/src/gui/interact/interaction-director.cpp b/src/gui/interact/interaction-director.cpp index fbe5ee31b..8b7470c2e 100644 --- a/src/gui/interact/interaction-director.cpp +++ b/src/gui/interact/interaction-director.cpp @@ -140,7 +140,7 @@ namespace interact { }) .matchElement ([&](GenNode const& spec, TimelineGui const& elm) -> bool { // »Matcher« : how to know we're dealing with the right timeline object - return spec.idi == ID(elm); + return spec.idi == ID{elm}; }) .constructFrom ([&](GenNode const& spec) -> TimelineGui { // »Constructor« : what to do when the diff mentions a new entity @@ -148,7 +148,7 @@ namespace interact { }) .buildChildMutator ([&](TimelineGui& targetTimeline, GenNode::ID const& subID, TreeMutator::Handle buff) -> bool { // »Mutator« : how to apply the diff recursively to a nested scope - if (ID(targetTimeline) != subID) return false; + if (ID{targetTimeline} != subID) return false; targetTimeline.buildMutator (buff); // - delegate to child(Timeline) to build nested TreeMutator return true; })) diff --git a/src/gui/timeline/clip-presenter.cpp b/src/gui/timeline/clip-presenter.cpp index 411e10c5d..19e30f7c7 100644 --- a/src/gui/timeline/clip-presenter.cpp +++ b/src/gui/timeline/clip-presenter.cpp @@ -99,15 +99,15 @@ namespace timeline { }) .matchElement ([&](GenNode const& spec, PMarker const& elm) -> bool { - return spec.idi == ID(elm); + return spec.idi == ID{*elm}; }) .constructFrom ([&](GenNode const& spec) -> PMarker { - return make_unique(spec.idi, this->uiBus_); + return make_unique (spec.idi, this->uiBus_); }) .buildChildMutator ([&](PMarker& target, GenNode::ID const& subID, TreeMutator::Handle buff) -> bool { - if (ID(target) != subID) return false; + if (ID{*target} != subID) return false; target->buildMutator (buff); return true; })) @@ -118,15 +118,15 @@ namespace timeline { }) .matchElement ([&](GenNode const& spec, PEffect const& elm) -> bool { - return spec.idi == ID(elm); + return spec.idi == ID{*elm}; }) .constructFrom ([&](GenNode const& spec) -> PEffect { - return make_unique(spec.idi, this->uiBus_); + return make_unique (spec.idi, this->uiBus_); }) .buildChildMutator ([&](PEffect& target, GenNode::ID const& subID, TreeMutator::Handle buff) -> bool { - if (ID(target) != subID) return false; + if (ID{*target} != subID) return false; target->buildMutator (buff); return true; })) @@ -137,15 +137,15 @@ namespace timeline { }) .matchElement ([&](GenNode const& spec, PChannel const& elm) -> bool { - return spec.idi == ID(elm); + return spec.idi == ID{*elm}; }) .constructFrom ([&](GenNode const& spec) -> PChannel { - return make_unique(spec.idi, this->uiBus_); + return make_unique (spec.idi, this->uiBus_); }) .buildChildMutator ([&](PChannel& target, GenNode::ID const& subID, TreeMutator::Handle buff) -> bool { - if (ID(target) != subID) return false; + if (ID{*target} != subID) return false; target->buildMutator (buff); return true; }))); diff --git a/src/gui/timeline/timeline-controller.cpp b/src/gui/timeline/timeline-controller.cpp index fa85ba73f..ede6fef58 100644 --- a/src/gui/timeline/timeline-controller.cpp +++ b/src/gui/timeline/timeline-controller.cpp @@ -144,7 +144,7 @@ namespace timeline { }) .matchElement ([&](GenNode const& spec, PMarker const& elm) -> bool { // »Matcher« : how to know we're dealing with the right object - return spec.idi == ID(elm); + return spec.idi == ID{*elm}; }) .constructFrom ([&](GenNode const& spec) -> PMarker { // »Constructor« : what to do when the diff mentions a new entity @@ -152,7 +152,7 @@ namespace timeline { }) .buildChildMutator ([&](PMarker& target, GenNode::ID const& subID, TreeMutator::Handle buff) -> bool { // »Mutator« : how to apply the diff recursively to a nested scope - if (ID(target) != subID) return false; // - require match on already existing child object + if (ID{*target} != subID) return false; // - require match on already existing child object target->buildMutator (buff); // - delegate to child to build nested TreeMutator return true; })) diff --git a/src/gui/timeline/timeline-gui.cpp b/src/gui/timeline/timeline-gui.cpp index aabe1ae04..8190b4d70 100644 --- a/src/gui/timeline/timeline-gui.cpp +++ b/src/gui/timeline/timeline-gui.cpp @@ -56,6 +56,8 @@ namespace timeline { , rootTrackID_{trackID} { } + TimelineGui::~TimelineGui() { } + /** * actually build a TimelineWidget to enact the role diff --git a/src/gui/timeline/timeline-gui.hpp b/src/gui/timeline/timeline-gui.hpp index fe03c30ea..59476467b 100644 --- a/src/gui/timeline/timeline-gui.hpp +++ b/src/gui/timeline/timeline-gui.hpp @@ -81,8 +81,12 @@ namespace timeline { public: TimelineGui (ID identity, ID trackID); + virtual ~TimelineGui(); - // standard copy operations aceptable + // standard copy operations acceptable + + + operator ID() const { return timelineID_; } /** actually build a TimelineWidget to enact the role diff --git a/src/gui/timeline/track-presenter.cpp b/src/gui/timeline/track-presenter.cpp index ea541c650..962e03a35 100644 --- a/src/gui/timeline/track-presenter.cpp +++ b/src/gui/timeline/track-presenter.cpp @@ -109,15 +109,15 @@ namespace timeline { }) .matchElement ([&](GenNode const& spec, PMarker const& elm) -> bool { - return spec.idi == ID(elm); + return spec.idi == ID{*elm}; }) .constructFrom ([&](GenNode const& spec) -> PMarker { - return make_unique(spec.idi, this->uiBus_); + return make_unique (spec.idi, this->uiBus_); }) .buildChildMutator ([&](PMarker& target, GenNode::ID const& subID, TreeMutator::Handle buff) -> bool { - if (ID(target) != subID) return false; + if (ID{*target} != subID) return false; target->buildMutator (buff); return true; })) @@ -128,15 +128,15 @@ namespace timeline { }) .matchElement ([&](GenNode const& spec, PClip const& elm) -> bool { - return spec.idi == ID(elm); + return spec.idi == ID{*elm}; }) .constructFrom ([&](GenNode const& spec) -> PClip { - return make_unique(spec.idi, this->uiBus_); + return make_unique (spec.idi, this->uiBus_); }) .buildChildMutator ([&](PClip& target, GenNode::ID const& subID, TreeMutator::Handle buff) -> bool { - if (ID(target) != subID) return false; + if (ID{*target} != subID) return false; target->buildMutator (buff); return true; })) @@ -147,15 +147,15 @@ namespace timeline { }) .matchElement ([&](GenNode const& spec, PFork const& elm) -> bool { - return spec.idi == ID(elm); + return spec.idi == ID{*elm}; }) .constructFrom ([&](GenNode const& spec) -> PFork { - return make_unique(spec.idi, this->uiBus_); + return make_unique (spec.idi, this->uiBus_); }) .buildChildMutator ([&](PFork& target, GenNode::ID const& subID, TreeMutator::Handle buff) -> bool { - if (ID(target) != subID) return false; + if (ID{*target} != subID) return false; target->buildMutator (buff); return true; }))); diff --git a/src/lib/diff/gen-node.hpp b/src/lib/diff/gen-node.hpp index 6b77c0f3f..41606287f 100644 --- a/src/lib/diff/gen-node.hpp +++ b/src/lib/diff/gen-node.hpp @@ -224,6 +224,7 @@ namespace diff{ { } public: + explicit ID (GenNode const& node) : ID(node.idi) { } diff --git a/src/lib/test/test-helper.hpp b/src/lib/test/test-helper.hpp index bb4141efc..dc5325dfe 100644 --- a/src/lib/test/test-helper.hpp +++ b/src/lib/test/test-helper.hpp @@ -147,6 +147,13 @@ namespace test{ static_assert (not sizeof(X), "### Type Debugging ###"); }; + template + void + typeDebugger(X&& x) + { + static_assert (not sizeof(X), "### Type Debugging ###"); + } + namespace { // helper for printing type diagnostics diff --git a/src/proc/asset.hpp b/src/proc/asset.hpp index 1a0905176..58b456a30 100644 --- a/src/proc/asset.hpp +++ b/src/proc/asset.hpp @@ -347,7 +347,7 @@ namespace asset { /** marker constant denoting a NIL asset */ template - ID ID::INVALID = ID(0); + ID ID::INVALID = ID{0}; }} // namespace proc::asset diff --git a/src/proc/streamtype.hpp b/src/proc/streamtype.hpp index a6475cc60..7522dc1e6 100644 --- a/src/proc/streamtype.hpp +++ b/src/proc/streamtype.hpp @@ -75,7 +75,7 @@ namespace proc { class ImplFacade; class ImplConstraint; - typedef lib::idi::EntryID ID; + using ID = lib::idi::EntryID; Prototype const& prototype; diff --git a/tests/core/proc/asset/basicpipetest.cpp b/tests/core/proc/asset/basicpipetest.cpp index 476619c66..0947d2f6e 100644 --- a/tests/core/proc/asset/basicpipetest.cpp +++ b/tests/core/proc/asset/basicpipetest.cpp @@ -64,9 +64,10 @@ namespace test { */ class BasicPipe_test : public Test { - virtual void run(Arg arg) + virtual void + run (Arg arg) { - string pipeID = isnil(arg)? "Black Hole" : arg[1]; + string pipeID = isnil (arg)? "Black Hole" : arg[1]; string streamID = 2>arg.size()? "teststream" : arg[2] ; createExplicit (pipeID,streamID); @@ -80,7 +81,7 @@ namespace test { void createExplicit (string pID, string sID) { - string pID_sane (pID); + string pID_sane{pID}; normaliseID (pID_sane); CHECK (pID_sane != pID); @@ -89,7 +90,7 @@ namespace test { CHECK (thePipe); CHECK (thePipe->getProcPatt()); CHECK (thePipe->getPipeID() == pID_sane); - CHECK (thePipe->getStreamID() == StreamType::ID(sID)); + CHECK (thePipe->getStreamID() == StreamType::ID{sID}); CHECK (thePipe->shortDesc == pID_sane); Asset::Ident idi = thePipe->ident; @@ -97,9 +98,9 @@ namespace test { CHECK (contains (idi.name, thePipe->getPipeID())); CHECK (contains (idi.name, thePipe->getStreamID())); - Category cat (idi.category); - Category refcat (STRUCT,"pipes"); - CHECK ( cat.hasKind(STRUCT) ); + Category cat{idi.category}; + Category refcat{STRUCT,"pipes"}; + CHECK ( cat.hasKind (STRUCT) ); CHECK ( cat.isWithin(refcat) ); } @@ -131,25 +132,25 @@ namespace test { PPipe pipe1 = Pipe::query (""); // "the default pipe" PPipe pipe2; CHECK (pipe1); - CHECK (pipe1 == Session::current->defaults (Query())); + CHECK (pipe1 == Session::current->defaults (Query{})); CHECK (pipe1->ident.category.hasKind(VIDEO)); CHECK (pipe1->getProcPatt()); - PProcPatt propa = Session::current->defaults (Query("pipe(default)")); + PProcPatt propa = Session::current->defaults (Query{"pipe(default)"}); CHECK (propa == pipe1->getProcPatt()); // several variants to query for "the default pipe" - pipe2 = Session::current->defaults(Query ()); + pipe2 = Session::current->defaults(Query{}); CHECK (pipe2 == pipe1); - pipe2 = asset::Struct::retrieve (Query ()); + pipe2 = asset::Struct::retrieve (Query{}); CHECK (pipe2 == pipe1); - pipe2 = asset::Struct::retrieve (Query ("pipe(default)")); + pipe2 = asset::Struct::retrieve (Query{"pipe(default)"}); CHECK (pipe2 == pipe1); string sID = pipe1->getStreamID(); // sort of a "default stream type" PPipe pipe3 = Pipe::query ("stream("+sID+")"); CHECK (pipe3); - CHECK (pipe3->getStreamID() == StreamType::ID(sID)); - CHECK (pipe3->getProcPatt() == Session::current->defaults (Query("stream("+sID+")"))); + CHECK (pipe3->getStreamID() == StreamType::ID{sID}); + CHECK (pipe3->getProcPatt() == Session::current->defaults (Query{"stream("+sID+")"})); } @@ -174,7 +175,7 @@ namespace test { // default pipe for this pattern automatically PPipe pipe2x = Pipe::query ("pattern(another)"); CHECK (pattern2 == pipe2x->getProcPatt()); - CHECK (pipe2x == Session::current->defaults (Query("pattern(another)"))); + CHECK (pipe2x == Session::current->defaults (Query{"pattern(another)"})); thePipe->switchProcPatt(pattern2); CHECK ( dependencyCheck (thePipe, pattern2)); @@ -197,7 +198,7 @@ namespace test { PPipe pipe3x = Pipe::query ("pattern(another)"); pattern3 = pipe3x->getProcPatt(); /////TODO: transition to P<> CHECK (pattern3 != pattern2); // because pattern2 is already unlinked... - CHECK (pipe3x == Session::current->defaults (Query("pattern(another)"))); + CHECK (pipe3x == Session::current->defaults (Query{"pattern(another)"})); CHECK (pipe3x != pipe2x); // ..we got a new default pipe for "pattern(another)" too! diff --git a/tests/core/proc/mobject/session/defs-manager-test.cpp b/tests/core/proc/mobject/session/defs-manager-test.cpp index a7db7369e..8225dcae8 100644 --- a/tests/core/proc/mobject/session/defs-manager-test.cpp +++ b/tests/core/proc/mobject/session/defs-manager-test.cpp @@ -128,16 +128,16 @@ namespace test { retrieveConstrainedDefault (string pID, string sID) { PPipe pipe1 = Pipe::query (""); // "the default pipe" - CHECK ( pipe1->getStreamID() != StreamType::ID(sID), + CHECK ( pipe1->getStreamID() != StreamType::ID{sID}, "stream-ID \"%s\" not suitable for test, because " "the default-pipe \"%s\" happens to have the same " "stream-ID. We need it to be different", sID.c_str(), pID.c_str() ); - string query_for_sID ("stream("+sID+")"); + string query_for_sID{"stream("+sID+")"}; PPipe pipe2 = Pipe::query (query_for_sID); - CHECK (pipe2->getStreamID() == StreamType::ID(sID)); + CHECK (pipe2->getStreamID() == StreamType::ID{sID}); CHECK (pipe2 != pipe1); CHECK (pipe2 == Pipe::query (query_for_sID)); // reproducible } @@ -146,13 +146,13 @@ namespace test { void failureCreatesNewDefault() { - PPipe pipe1 = Session::current->defaults(Query ("")); // "the default pipe" + PPipe pipe1 = Session::current->defaults(Query{""}); // "the default pipe" string new_pID = _Fmt{"dummy_%s_%i"} % pipe1->getPipeID() % std::rand() ; // make random new pipeID - Query query_for_new ("pipe("+new_pID+")"); + Query query_for_new{"pipe("+new_pID+")"}; CHECK (!find (query_for_new)); // check it doesn't exist PPipe pipe2 = Session::current->defaults (query_for_new); // triggers creation @@ -170,13 +170,13 @@ namespace test { void verifyRemoval() { - Symbol pID ("some_pipe"); - Query query_for_pID ("pipe("+pID+")"); + Symbol pID{"some_pipe"}; + Query query_for_pID{"pipe("+pID+")"}; size_t hash; { // create new pipe and declare it to be a default PPipe pipe1 = Struct::retrieve.newInstance (pID); - Session::current->defaults.define(pipe1); + Session::current->defaults.define (pipe1); CHECK (2 == pipe1.use_count()); // the pipe1 smart-ptr and the AssetManager hash = pipe1->getID(); diff --git a/tests/library/util-sanitised-identifier-test.cpp b/tests/library/util-sanitised-identifier-test.cpp index cdfd9f05b..bf8288715 100644 --- a/tests/library/util-sanitised-identifier-test.cpp +++ b/tests/library/util-sanitised-identifier-test.cpp @@ -46,7 +46,7 @@ namespace test { print_clean ("a Sentence"); print_clean ("trailing Withespace\n \t"); print_clean ("with a \t lot\n of Whitespace"); - print_clean ("with\"much (punctuation)[]!"); + print_clean ("@with\".\'much ($punctuation)[]!"); print_clean ("§&Ω%€ leading garbage"); print_clean ("mixed Ω garbage"); print_clean ("Bääääh!!");