Skip to content

Applications compiled on MacOS with -Wshadow report warnings from 14 ROOT headers #20790

@kelseymh

Description

@kelseymh

Check duplicate issues.

  • Checked for duplicates

Description

As reported in the ROOT forums in 2019, https://root-forum.cern.ch/t/shadow-warnings-when-compiling-against-root, when a user application is compiled against ROOT on MacOS (reported under 10.15.7/Catalina, still present with Tahoe 26.2), there are fourteen ROOT files which generate compiler warnings via -Wshadow, because they define local enumerator names which duplicate global namespace enums. For example:

<ROOTSYS>/include/root/TBranch.h:108:7: warning: declaration shadows a variable in the global namespace [-Wshadow]
  108 |       kBranchAny    = ::kBranchAny,    ///< Branch is an object*
      |       ^
<ROOTSYS>/include/root/TBranch.h:59:13: note: previous declaration is here
   59 | const Int_t kBranchAny    = BIT(17); // branch is an object*
      |             ^

Following the guidance from @pcanal in that post, I was able to suppress the warnings (but not fix the underlying potential conflict) by adding #pragma directives at the top and bottom of the affected files:

core/base/inc/TApplication.h
core/base/inc/TAttMarker.h
core/base/inc/TSystem.h
core/base/inc/TVirtualX.h
core/meta/inc/TClass.h
core/meta/inc/TInterpreter.h
gui/gui/inc/TGFrame.h
io/io/inc/TFile.h
math/matrix/inc/TMatrixT.h
math/matrix/inc/TMatrixTSparse.h
math/matrix/inc/TMatrixTSym.h
net/net/inc/TSocket.h
tree/tree/inc/TBranch.h

I have copied over from Forums user vaubee a minimal example to demonstrate the problem using TBranch.h.

Reproducer

#include
#include "TROOT.h"
#include "TBranch.h"

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

Comple this on MacOS with clang++ -o test test.cc $(root-config --cflags --libs) -Wshadow

ROOT version

All ROOT versions since at least 6.12/06. Reproduced most recently with 6.36.06.

Installation method

Homebrew (brew install root)

Operating system

MacOS Catalina through Tahoe

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions