Shadow warnings when compiling against ROOT


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?

Hi,

We are compiling normally with -Wshadow and we do not get this warning. I guess something is wrong when compiling your application

Lorenzo

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

to compile this test.cc file:

#include <iostream>
#include "TROOT.h"
#include "TBranch.h"

int main(int, char**)
{
        std::cout<<TROOT::GetMacroPath()<<std::endl;

        return 0;
}

EDIT: This is using ROOT installed using mac ports variant cocoa, davix, graphviz, gsl, opengl, python38, roofit, tmva, xml, and xrootd

HI,

I compiled with -Wshadow but in another architecture (linux ubuntu with gcc) not in Catalina.Maybe @pcanal has an answer for this

Lorenzo

Oh yes, I should have mentioned that I only have this issue on mac os using clang, not on CentOS using gcc.

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

#ifdef __CLANG___
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshadow"
#endif

#ifdef __CLANG___
#pragma clang diagnostic pop
#endif

and propose a PR?

Thanks
Philippe.

1 Like

That doesn’t change the warning, it only changes the line number of the warning.

That is because I used the wrong casing and wrong syntax … I meant:

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshadow"
#endif

#if defined(__clang__)
#pragma clang diagnostic pop
#endif

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).

1 Like

If you can, please submit a PR with your changes (at https://github.com/root-project/root/pulls)

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