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
^ ~~~~~~~~~~~~~~~~~~~~~~~
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 … ).