Skip to content

Commit 0ef4f35

Browse files
committed
Avoid compiler warning in rootcling and rootcling_stage1
Warning: root/core/rootcling_stage1/src/rootcling_stage1.cxx(38): warning root-project#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.
1 parent 96bdfc2 commit 0ef4f35

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

core/rootcling_stage1/src/rootcling_stage1.cxx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ extern "C" {
1717
R__DLLEXPORT void usedToIdentifyRootClingByDlSym() {}
1818
}
1919

20+
// force compiler to emit symbol for function above
21+
static void (*dlsymaddr)() = &usedToIdentifyRootClingByDlSym;
2022

2123
ROOT::Internal::RootCling::TROOTSYSSetter gROOTSYSSetter;
2224

@@ -32,12 +34,7 @@ static const char *GetEtcDir() {
3234

3335
int main(int argc, char **argv)
3436
{
35-
// Force the emission of the symbol - the compiler cannot know that argv
36-
// is always set.
37-
if (!argv) {
38-
auto dummyVal = (int)(long)&usedToIdentifyRootClingByDlSym;
39-
return dummyVal;
40-
}
37+
(void) dlsymaddr; // avoid unused variable warning
4138

4239
ROOT::Internal::RootCling::DriverConfig config{};
4340

main/src/rootcling.cxx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ extern "C" {
1919
R__DLLEXPORT void usedToIdentifyRootClingByDlSym() {}
2020
}
2121

22+
// force compiler to emit symbol for function above
23+
static void (*dlsymaddr)() = &usedToIdentifyRootClingByDlSym;
24+
2225
int main(int argc, char **argv)
2326
{
24-
// Force the emission of the symbol - the compiler cannot know that argv
25-
// is always set.
26-
if (!argv) {
27-
auto dummyVal = (int)(long)&usedToIdentifyRootClingByDlSym;
28-
return dummyVal;
29-
}
27+
(void) dlsymaddr; // avoid unused variable warning
3028

3129
ROOT::Internal::RootCling::DriverConfig config{};
3230

0 commit comments

Comments
 (0)