New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix GCC 7 errors (inc. buffer size and fix TString conversion) #17443
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1090,7 +1090,7 @@ HIPAlignmentAlgorithm::calcAPE(double* par, int iter, double function) | |
void HIPAlignmentAlgorithm::bookRoot(void) | ||
{ | ||
TString tname="T1"; | ||
char iterString[5]; | ||
char iterString[15]; | ||
snprintf(iterString, sizeof(iterString), "%i",theIteration); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where did you get this number from? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as previous, compiler error/notes tell the potential buffer size. |
||
tname.Append("_"); | ||
tname.Append(iterString); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -837,7 +837,7 @@ void MuonAlignmentAnalyzer::endJob(){ | |
|
||
|
||
|
||
char binLabel[15]; | ||
char binLabel[40]; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where did you get this number from? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GCC error message provides information of min / max sizes for the buffer. e.g,
|
||
for(unsigned int i=0 ; i<unitsLocalX.size() ; i++) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davidlt wouldn't it be sufficient to write this:
as the compiler knows how to convert a char to string?
Naively I would expect if we assign to a
std::string
the rhs will be implicitely converted to this type w/o going through another type. Or does the compiler optimize code such that it changes the type ofmeas.name_
fromstd::string
tostd::string_view
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implicit conversion is possible. Thus the following would work:
Which is basically the same as
std::string(pos2D->GetID().Data())
, becausestd::string
has constructor which takesconst char *
and compiler can map that.The problem is that
TString
has conversion functions toconst char *
andstd::string_view
, but the same are also available instd::string
constructors. This means means we have two ways to constructor a string (or do things like +=) and they have the same priority. For compiler that's ambiguity -- it doesn't know which to pick. For example, the one below would force the compiler to pickconst char *
conversion operator ofTString
:As you can see there multiple ways you can write this. I depends how much you want to be explicit about what needs to happen or not, but end result (executed code) should be the same. One could write full chain explicitly instead of implicitly done by compiler: