|
[Rivet] Dangerous casting to FinalStateFrank Siegert frank.siegert at cern.chTue Mar 10 14:49:00 GMT 2015
Hi Riveters, just a short warning about a tricky mistake that can happen quite easily. Example1: FinalState remainder = zfinder.remainingFinalState(); addProjection(remainder, "RFS"); Example2a: const FinalState& remainder = zfinder.remainingFinalState(); addProjection(remainder, "RFS"); Example2b: addProjection(zfinder.remainingFinalState(), "RFS"); Example 2c: VetoedFinalState remainder = zfinder.remainingFinalState(); addProjection(remainder, "RFS"); All of them will compile fine, but the first one will behave differently from the others. Since the object is copied instead of passed by reference the remainder object will actually not be aware of its "VetoedFinalState" properties and thus not apply any vetoing at all. This is all fine, and Rivet is behaving correctly as expected from C++, but it's nevertheless tricky to overlook. Does anybody have an idea how to avoid this for users who don't pay close enough attention? Is there any reasonable way of hiding/masking the copy constructor for such cases? Cheers, Frank
More information about the Rivet mailing list |