TDirectory operator= is deleted

ROOT Version: 6.24.06
Platform: Linux
Compiler: gcc

Dear ROOT developers,
TDirectory’s copy assignment operator is implicitly deleted
What would be the correct form of this code:

auto cwd = gDirectory;
gDirectory = nullptr;
//do somethings here 
gDirectory = cwd;

Regards,
Nikolay

Using “auto” (anywhere in ROOT) means that you do not actually know what you are doing and why.
Use a proper: TDirectory *cwd = gDirectory;

BTW. @Axel You’ve introduced a real incompatibility in ROOT 6.24:

root [0] gROOT // the actual current directory
(TROOT *) 0x7feb7ee770e0
root [1] gDirectory // not a TDirectory pointer any more
(ROOT::Internal::TDirectoryAtomicAdapter) @0x5619a5d99170
root [2] (TDirectory*)gDirectory // still returns the current directory
(TDirectory *) 0x7feb7ee770e0
root [3] auto cwd = (TDirectory*)gDirectory // what is this then?
(TDirectory *) @0x7ffdaf6bdee8
root [4] TDirectory *&cwd = gDirectory // this dies
ROOT_prompt_4:1:14: error: non-const lvalue reference to type 'TDirectory *' cannot bind to a temporary of type 'ROOT::Internal::TDirectoryAtomicAdapter'
TDirectory *&cwd = gDirectory // this dies
             ^     ~~~~~~~~~~
root [5] TDirectory *&cwd = (TDirectory*)gDirectory // this dies, too
ROOT_prompt_5:1:14: error: non-const lvalue reference to type 'TDirectory *' cannot bind to a temporary of type 'TDirectory *'
TDirectory *&cwd = (TDirectory*)gDirectory // this dies, too
             ^     ~~~~~~~~~~~~~~~~~~~~~~~

Thank you @Wile_E_Coyote !

Hi @Wile_E_Coyote could you cross-check with printf? There’s an open bug in cling where the value printer fails with variables of point type…

This is not really new (end of 2020, see 085e9c182b9f639d5921c75de284ae7f20168b6e and was necessary to fix ’ #6939 gDirectory in one thread pointed to TFile deleted in another thread.’)

root [3] auto cwd = (TDirectory*)gDirectory // what is this then?

The adapter has an operator TDirectory*

root [4] TDirectory *&cwd = gDirectory // this dies

Indeed this can no longer be supported (but hopefully is not actually used … ).

Instead of :

Use:

{
    TDirectory::TContext ctxt;  // Default to swiching the gDirectory to nullptr.
    // do somethings here 
}

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.