Skip to content

Remove implicit conversion from MCVertex* to MCVertex

Without the fix in this MR, the following code will compile:

  constexpr auto hello = [](const LHCb::MCVertex&) { std::cout << "hello world\n"; };
  auto ptr = new LHCb::MCVertex();
  hello(ptr); // note: `hello` requires a reference, and ptr is a _pointer_

because the following bit of code was present:

    /// Copy Constructor
    MCVertex( const LHCb::MCVertex* right )

This is NOT a copy constructor -- it is constructor, which is eligible for implicit conversion, from a pointer to an MCVertex to an MCVertex. So when one calls a function which requires a const LHCb::MCVertex& with a pointer as argument instead, it will silently create a (temporary!) object from the pointed-to MCVertex.

This MR labels this constructor as explicit and [[deprecated]] so that it will no longer be used by accident (ideally, it should never be used).

Note that removal of this implicit conversion will affect code using this (erroneously) -- two such examples are fixed by Rec!4206 and Allen!1851

Edited by Gerhard Raven

Merge request reports

Loading