Skip to content

Commit 79d8b18

Browse files
authored
[core][RF][misc][interpreter] Fix various compiler warnings
* [RF] fix windows warning C:\ROOT-CI\src\roofit\roofitcore\src\RooLinkedList.cxx(71,19): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?) [C:\ROOT-CI\build\roofit\roofitcore\RooFitCore.vcxproj] * [core] fix unused var warning * Update RooLinkedList.cxx * [misc] fix win32 main return warning warning C4326: return type of 'main' should be 'int' instead of 'void' * [RF] unsafe mix int bool warning C4805: '|=': unsafe mix of type 'int' and type 'bool' in operation * [RF] use nullptr and fix typo * [RF] fix unsafe mix int bool warning C4805: '|=': unsafe mix of type 'int' and type 'bool' in operation * [RF] cast bool to int warning C4804: '/': unsafe use of type 'bool' in operation * [io,test] fix overflow warning warning C4756: overflow in constant arithmetic * [tmva,sofie] fix win warnings discarding return value of function with [[nodiscard]] attribute * [llvm] silence some windows warnings * [RF] fix wrong ret value and fix warning * Apply suggestions from code review Co-authored-by: ferdymercury <ferdymercury@users.noreply.github.com> * Update w32pragma.h * Apply suggestion from @ferdymercury * [core] print exception message Co-authored-by: ferdymercury <ferdymercury@users.noreply.github.com>
1 parent 8c6fbdc commit 79d8b18

9 files changed

Lines changed: 27 additions & 20 deletions

File tree

cmake/win/w32pragma.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
#pragma warning (disable: 4503)
5050

5151
/* function is hidden */
52-
#pragma warning (3: 4266)
52+
#pragma warning (disable: 4266)
5353
/* loop control variable is used outside the for-loop scope */
5454
#pragma warning (3: 4289)
5555

core/base/src/TROOT.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ namespace {
340340
try {
341341
desiredValue = std::stoi(env);
342342
} catch (std::invalid_argument &e) {
343-
Error("TROOT", "%s should be 0 or 1", envName);
343+
Error("TROOT", "%s should be 0 or 1, exception message: '%s'", envName, e.what());
344344
}
345345
if (desiredValue == 0) {
346346
autoReg = AutoReg::kOff;

io/io/test/TBufferJSONTests.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,14 @@ TEST(TBufferJSON, SpecialNumbersFloat)
119119
p = nullptr;
120120

121121
auto maxVal = std::numeric_limits<float>::max(); // 3.40282e+38f
122+
#ifdef WIN32
123+
#pragma warning( push )
124+
#pragma warning( disable : 4756 ) // overflow in constant arithmetic
125+
#endif
122126
auto ovfVal = std::numeric_limits<float>::max() * static_cast<float>(1 + 1e-7);
127+
#ifdef WIN32
128+
#pragma warning( pop )
129+
#endif
123130
auto infVal = std::numeric_limits<float>::infinity();
124131
EXPECT_EQ(ovfVal, infVal);
125132
auto nanVal = std::numeric_limits<float>::quiet_NaN();

misc/win/bindexplib/bindexplib.cxx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ void bindexplib::WriteFile(FILE *file)
470470
}
471471

472472

473-
void
473+
int
474474
main(int argc, char **argv)
475475
{
476476
std::string cmdline;
@@ -484,7 +484,7 @@ main(int argc, char **argv)
484484
if (argc < 3) {
485485
Usage:
486486
fprintf(stderr, "Usage: %s ?-o outfile? ?-f(ull)? <dllname> <object filenames> ..\n", argv[0]);
487-
exit(1);
487+
return EXIT_FAILURE;
488488
}
489489

490490
arg = 1;
@@ -515,7 +515,7 @@ main(int argc, char **argv)
515515
fprintf(stderr, "Unable to open \'%s\' for writing:\n",
516516
argv[arg]);
517517
perror("");
518-
exit(1);
518+
return EXIT_FAILURE;
519519
}
520520
} else {
521521
fout = stdout;
@@ -543,7 +543,7 @@ main(int argc, char **argv)
543543
fprintf(stderr, "Unable to open \'%s\' for reading:\n",
544544
argv[arg]);
545545
perror("");
546-
exit(1);
546+
return EXIT_FAILURE;
547547
}
548548
char *fargv[1000];
549549
for (i = 0; i < arg; i++) {
@@ -566,7 +566,7 @@ main(int argc, char **argv)
566566
if (SearchFile == INVALID_HANDLE_VALUE) {
567567
fprintf(stderr, "Unable to find \'%s\' for reading:\n",
568568
argv[arg]);
569-
exit(1);
569+
return EXIT_FAILURE;
570570
} else {
571571
/*
572572
* Since WIN32_FIND_DATA has no path information one has to extract it oneself.
@@ -588,5 +588,5 @@ main(int argc, char **argv)
588588
deffile.WriteFile(fout);
589589
}
590590
}
591-
exit(0);
591+
return EXIT_SUCCESS;
592592
}

roofit/batchcompute/src/ComputeFunctions.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ __rooglobal__ void computeGamma(Batches &batches)
399399
double gamma = -std::lgamma(G[0]);
400400
for (size_t i = BEGIN; i < batches.nEvents; i += STEP) {
401401
if (X[i] == M[i]) {
402-
batches.output[i] = (G[i] == 1.0) / B[i];
402+
batches.output[i] = int(G[i] == 1.0) / B[i];
403403
} else if (G._isVector) {
404404
batches.output[i] = -std::lgamma(G[i]);
405405
} else {

roofit/roofit/test/testFitPerf.cxx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,12 +563,12 @@ int FitUsingRooFit(TTree *tree, TF1 *func)
563563
#ifdef DEBUG
564564
mean.Print();
565565
sigma.Print();
566-
assert(result != 0);
566+
assert(result != nullptr);
567567
std::cout << " Roofit status " << result->status() << std::endl;
568568
result->Print();
569569
#endif
570570
if (save)
571-
iret |= (result == 0);
571+
iret |= int(result == nullptr);
572572

573573
if (iret != 0) {
574574
std::cout << "Fit failed " << std::endl;
@@ -648,12 +648,12 @@ int FitUsingRooFit2(TTree *tree)
648648
pdf[N - 1]->fitTo(data, RooFit::Minos(0), RooFit::Hesse(1), RooFit::PrintLevel(level), RooFit::Save(save))};
649649

650650
#ifdef DEBUG
651-
assert(result != 0);
652-
std::cout << " Roofit status " << result->status() << std::endl;
653-
result->Print();
651+
assert(result == nullptr);
652+
//std::cout << " Roofit status " << result->status() << std::endl;
653+
//result->Print();
654654
#endif
655655

656-
iret |= (result != 0);
656+
iret |= int(result != nullptr);
657657

658658
if (iret != 0)
659659
return iret;

roofit/roofit/test/testRooFit.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ int FitUsingRooFit(TTree &tree, RooAbsPdf &pdf, RooArgSet &xvars)
209209
std::cout << " Roofit status " << result->status() << std::endl;
210210
result->Print();
211211
#endif
212-
iret |= (result == nullptr);
212+
iret |= int(result == nullptr);
213213
}
214214

215215
w.Stop();

roofit/roofitcore/src/RooLinkedList.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ namespace RooLinkedListImplDetails {
6868
~Chunk() { delete[] _chunk; }
6969
/// chunk capacity
7070
Int_t capacity() const
71-
{ return (1 << _sz) / sizeof(RooLinkedListElem); }
71+
{ return (1ULL << _sz) / sizeof(RooLinkedListElem); }
7272
/// chunk free elements
7373
Int_t free() const { return _free; }
7474
/// chunk occupied elements

tmva/sofie/src/RModel.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ void RModel::ReadInitializedTensorsFromFile(long pos) {
15491549
fGC += " fTensor_" + i.first + " = *reinterpret_cast<std::vector<int64_t>*>(rootFile->Get(\"";
15501550
fGC += dirName + "/" + tensor_name + "\"));\n";
15511551
} else {
1552-
std::runtime_error("tmva-sofie tensor " + tensor_name + " with type " + ConvertTypeToString(i.second.type()) + " cannot be read from a ROOT file");
1552+
throw std::runtime_error("tmva-sofie tensor " + tensor_name + " with type " + ConvertTypeToString(i.second.type()) + " cannot be read from a ROOT file");
15531553
}
15541554
fGC += " }\n";
15551555
}
@@ -1617,7 +1617,7 @@ long RModel::WriteInitializedTensorsToFile(std::string filename) {
16171617
outputDir->WriteObjectAny(&tensorDataVector, "std::vector<int64_t>", tensorName.c_str());
16181618
}
16191619
else {
1620-
std::runtime_error("tmva-sofie tensor " + tensorName + " with type " + ConvertTypeToString(item.second.type()) +
1620+
throw std::runtime_error("tmva-sofie tensor " + tensorName + " with type " + ConvertTypeToString(item.second.type()) +
16211621
" cannot be written to a ROOT file");
16221622
}
16231623
}
@@ -1668,7 +1668,7 @@ long RModel::WriteInitializedTensorsToFile(std::string filename) {
16681668
throw std::runtime_error("tmva-sofie tensor " + tensor_name + " with type " + ConvertTypeToString(i.second.type()) + " cannot be written to a file");
16691669
}
16701670
if (f.fail())
1671-
std::runtime_error("tmva-sofie failed to write tensor data to file for " + tensor_name);
1671+
throw std::runtime_error("tmva-sofie failed to write tensor data to file for " + tensor_name);
16721672
}
16731673
long curr_pos = f.tellp();
16741674
f.close();

0 commit comments

Comments
 (0)