ROOT Version: 6.18/04 Platform: MacOS 10.15 Catalina Compiler: Apple clang version 11.0.0 (clang-1100.0.33.12)
When compiling a program against ROOT I get a lot of shadow warnings like this:
In file included from /opt/local/libexec/root6/include/root/TTree.h:36:
/opt/local/libexec/root6/include/root/TBranch.h:76:7: warning: declaration shadows a variable in the global namespace [-Wshadow]
kDoNotProcess = ::kDoNotProcess, // Active bit for branches
^
/opt/local/libexec/root6/include/root/TBranch.h:53:16: note: previous declaration is here
const Int_t kDoNotProcess = BIT(10); // Active bit for branches
^
/opt/local/libexec/root6/include/root/TBranch.h:77:7: warning: declaration shadows a variable in the global namespace [-Wshadow]
kIsClone = ::kIsClone, // to indicate a TBranchClones
^
/opt/local/libexec/root6/include/root/TBranch.h:54:16: note: previous declaration is here
const Int_t kIsClone = BIT(11); // to indicate a TBranchClones
^
/opt/local/libexec/root6/include/root/TBranch.h:78:7: warning: declaration shadows a variable in the global namespace [-Wshadow]
kBranchObject = ::kBranchObject, // branch is a TObject*
^
/opt/local/libexec/root6/include/root/TBranch.h:55:16: note: previous declaration is here
const Int_t kBranchObject = BIT(12); // branch is a TObject*
^
/opt/local/libexec/root6/include/root/TBranch.h:79:7: warning: declaration shadows a variable in the global namespace [-Wshadow]
kBranchAny = ::kBranchAny, // branch is an object*
^
/opt/local/libexec/root6/include/root/TBranch.h:56:16: note: previous declaration is here
const Int_t kBranchAny = BIT(17); // branch is an object*
The compiled program seems to work fine, but getting screens full of warnings from ROOT (there are similar warnings from TSystem.h, TMatrixT.h&TAddMarker.h, TTree.h&TError.h, and others) makes it hard to spot any warnings about my own code.
Is this something that will be addressed in newer versions of ROOT? Or is there a way (apart from disabling -Wshadow) to suppress these warnings?
Interesting. So you’re compiling with the same ROOT version on Catalina and you don’t get these errors? Because it seems to be complaining about variables in TBranch.h shadowing other variables in the same file. And I can reproduce the error when using
clang++ -o test test.cc `root-config --cflags --libs` -Wshadow
I am guessing it is a ‘new’ warning from clang. Unfortunately the shadowing here is actually intentional, part of a (small) deprecating of name set in the global namespace. Could try modifying TBranch.h to add the ‘proper’ version of
Yes, that fixed the warning. I had to do this for TBranch.h, TTree.h, TGFrame.h, TInterpreter.h, TMatrixT.h, TMatrixTSym.h, TSystem.h, TClass.h, TFile.h, TApplication.h, TVirtualX.h, TSocket.h, TMatrixTSparse.h and TAttMarker.h.
Of course those are just the ones used in our program that came up with this so there might be more files that need this …
EDIT: I should also point out that the first part should be put at the top of the file, the second part at the bottom so that they straddle the line where the error occurs (just in case anyone finds this at a later search).