From 95d9fb57c206c556b79ac9678e93544cf688da27 Mon Sep 17 00:00:00 2001 From: Guilherme Amadio Date: Wed, 12 Jul 2017 15:23:51 +0200 Subject: [PATCH] Avoid compiler warning in rootcling and rootcling_stage1 Warning: root/core/rootcling_stage1/src/rootcling_stage1.cxx(38): warning #69: integer conversion resulted in truncation auto dummyVal = (int)(long)&usedToIdentifyRootClingByDlSym; ^^^ The method above uses a cast to long, followed by a cast to int, which results in a truncation. That is harmless, since the value is never used, but generates a compiler warning with ICC 17. This commit avoids the warning by storing the address of the same symbol in a static variable instead. --- core/rootcling_stage1/src/rootcling_stage1.cxx | 9 +++------ main/src/rootcling.cxx | 10 ++++------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/core/rootcling_stage1/src/rootcling_stage1.cxx b/core/rootcling_stage1/src/rootcling_stage1.cxx index 44f83c0d31556..ffb5a7ef3ae4d 100644 --- a/core/rootcling_stage1/src/rootcling_stage1.cxx +++ b/core/rootcling_stage1/src/rootcling_stage1.cxx @@ -17,6 +17,8 @@ extern "C" { R__DLLEXPORT void usedToIdentifyRootClingByDlSym() {} } +// force compiler to emit symbol for function above +static void (*dlsymaddr)() = &usedToIdentifyRootClingByDlSym; ROOT::Internal::RootCling::TROOTSYSSetter gROOTSYSSetter; @@ -32,12 +34,7 @@ static const char *GetEtcDir() { int main(int argc, char **argv) { - // Force the emission of the symbol - the compiler cannot know that argv - // is always set. - if (!argv) { - auto dummyVal = (int)(long)&usedToIdentifyRootClingByDlSym; - return dummyVal; - } + (void) dlsymaddr; // avoid unused variable warning ROOT::Internal::RootCling::DriverConfig config{}; diff --git a/main/src/rootcling.cxx b/main/src/rootcling.cxx index d06fdb32dc814..8165ce2e1293a 100644 --- a/main/src/rootcling.cxx +++ b/main/src/rootcling.cxx @@ -19,14 +19,12 @@ extern "C" { R__DLLEXPORT void usedToIdentifyRootClingByDlSym() {} } +// force compiler to emit symbol for function above +static void (*dlsymaddr)() = &usedToIdentifyRootClingByDlSym; + int main(int argc, char **argv) { - // Force the emission of the symbol - the compiler cannot know that argv - // is always set. - if (!argv) { - auto dummyVal = (int)(long)&usedToIdentifyRootClingByDlSym; - return dummyVal; - } + (void) dlsymaddr; // avoid unused variable warning ROOT::Internal::RootCling::DriverConfig config{};