root icon indicating copy to clipboard operation
root copied to clipboard

Consider (re)allowing a template constructor to be use as IO Constructor.

Open pcanal opened this issue 6 months ago • 2 comments

Feature description

In v5, if you have a class (see roottest/root/io/alloc)

class WithTemplate {
public:
   WithTemplate() { cout << "Called WithTemplate::WithTemplate()\n"; }
   template <class T> WithTemplate(T*) {
      cout << "Called WithTemplate::WithTemplate<T>() T=" << typeid(T*).name() << "\n"; 
   }
};

and also had in the LinkDef:

// Seen in the test
#pragma link C++ function WithTemplate::WithTemplate(OTHER_ROOT_IO*);
#pragma link C++ ioctortype OTHER_ROOT_IO;
// or simply
#pragma link C++ function WithTemplate::WithTemplate(TRootIOCtor*);

then the instance of the templated constructor would be used as the I/O constructor.

In v6, the pragma link function are no-op (as the whole header file can/is just in time compiled/interpreted).

The code in rootcling is also not 'forcing' the instantiation of the function template (when looking for I/O constructor) and thus the templated constructor are effectively no longer considered as potential I/O constructor. (We have not tested/investigated if one can request an explicit instantiation and have it considered).

This is a backward incompatibility between v5 and v6.

A workaround is to write a concrete implementation of the I/O Constructor.

Alternatives considered

No response

Additional context

No response

pcanal avatar Jun 11 '25 15:06 pcanal

Any action/decision of this issue should be reflected in roottest/root/io/alloc.

pcanal avatar Jun 11 '25 15:06 pcanal

Thanks for opening this issue - this is indeed subtle. Since the start of Run2, we received no request of this feature: is this a sign that it's not needed?

dpiparo avatar Jun 14 '25 08:06 dpiparo