Using defaulted ctor on TObject derived classes?

From the below Pull Request on Github I learned that using = default; to create a defaulted ctor for TNamed introduces some issues. I have not fully understood those.

This confuses me somewhat:

If I create a normal user defined class that derives from TObject (I hope that’s generally okay?!), should I avoid using = default; on the default ctor?

If this is really the case: How can I check for the default ctor being valid in my unit tests? Is there some test helper function in ROOT that helps me check my default ctor?

ROOT Version: latest
Platform: any?
Compiler: any?

There is magic code in TObject constructor which allows us to distinguish
if object created with new operator or as stack variable. In first case
object should be cleaned up - via ROOT cleanup lists.

All this does not work if = default constructor is used.
Therefore all ROOT classes (especially graphics-related) do not use such constructors declaration.

For your particular case it depends if objects ownership handled properly.
Means you destroy it, add to TList with ownership flag and so on.
In such case you can use = default constructor.

Probably @pcanal can give better explanation.

1 Like

There is simple test:

auto obj = new MyType{}
if (! obj->IsOnHeap())
   throw "TObject::IsOnHeap is broken for MyType";
delete obj;
1 Like