Skip to content
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

Merged
merged 1 commit into from Feb 10, 2017

Conversation

davidlt
Copy link
Contributor

@davidlt davidlt commented Feb 7, 2017

TString supports conversions to std::string and std::string_view in
C++17 which causes ambiguity as std::string ctors and operators support
both also. Compiler cannot decide which one to use. We have either call
explicitly conversion operatator on TString (e.g., via static_cast) or
use other methods (e.g. construct std::string from const char * TString::Data()).

In some cases compiler says that buffers are too small.

TStrings could also be removed and replaced with C++ standard functions.

Signed-off-by: David Abdurachmanov David.Abdurachmanov@cern.ch

TString supports conversions to std::string and std::string_view in
C++17 which causes ambiguity as std::string ctors and operators support
both also. Compiler cannot decide which one to use. We have either call
explicitly conversion operatator on TString (e.g., via static_cast) or
use other methods (e.g. construct std::string from const char *
TString::Data()).

In some cases compiler says that buffers are too small.

TStrings could also be removed and replaced with C++ standard functions.

Signed-off-by: David Abdurachmanov <David.Abdurachmanov@cern.ch>
@cmsbuild
Copy link
Contributor

cmsbuild commented Feb 7, 2017

A new Pull Request was created by @davidlt for CMSSW_9_0_X.

It involves the following packages:

Alignment/CocoaModel
Alignment/CommonAlignmentMonitor
Alignment/HIPAlignmentAlgorithm
Alignment/OfflineValidation

@ghellwig, @arunhep, @cerminar, @cmsbuild, @franzoni, @mmusich, @davidlange6 can you please review it and eventually sign? Thanks.
@ghellwig, @pakhotin, @tocheng, @tlampen, @mschrode, @mmusich this is something you requested to watch as well.
@davidlange6, @smuzaffar you are the release manager for this.

cms-bot commands are listed here #13028

@davidlt
Copy link
Contributor Author

davidlt commented Feb 7, 2017

please test

@cmsbuild
Copy link
Contributor

cmsbuild commented Feb 7, 2017

The tests are being triggered in jenkins.
https://cmssdt.cern.ch/jenkins/job/ib-any-integration/17666/console Started: 2017/02/07 15:49

@cmsbuild
Copy link
Contributor

cmsbuild commented Feb 7, 2017

@cmsbuild
Copy link
Contributor

cmsbuild commented Feb 7, 2017

Comparison job queued.

@cmsbuild
Copy link
Contributor

cmsbuild commented Feb 7, 2017

@@ -128,7 +129,7 @@ OpticalAlignMeasurementInfo CocoaDaqReaderRoot::GetMeasFromPosition2D( AliDaqPos
OpticalAlignMeasurementInfo meas;

meas.type_ = "SENSOR2D";
meas.name_ = pos2D->GetID();

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:

meas.name_ = pos2D->GetID().Data();

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 of meas.name_ from std::string to std::string_view?

Copy link
Contributor Author

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:

meas.name_ = pos2D->GetID().Data();

Which is basically the same as std::string(pos2D->GetID().Data()), because std::string has constructor which takes const char * and compiler can map that.

The problem is that TString has conversion functions to const char * and std::string_view, but the same are also available in std::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 pick const char * conversion operator of TString:

meas.name_ = static_cast<const char *>(pos2D->GetID());

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:

meas.name_ = std::string(static_cast<const char *>(pos2D->GetID()));

@@ -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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did you get this number from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous, compiler error/notes tell the potential buffer size.

@@ -837,7 +837,7 @@ void MuonAlignmentAnalyzer::endJob(){



char binLabel[15];
char binLabel[40];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did you get this number from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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,

Alignment/OfflineValidation/plugins/MuonAlignmentAnalyzer.cc:1371:25: note: 'snprintf' output between 18 and 38 bytes into a destination of size 15

More here: https://cmssdt.cern.ch/SDT/cgi-bin/buildlogs/slc6_amd64_gcc700/CMSSW_9_0_X_2017-02-10-1100/Alignment/OfflineValidation

@ghellwig
Copy link

+1
@davidlt thanks for the additional information!

@cmsbuild
Copy link
Contributor

This pull request is fully signed and it will be integrated in one of the next CMSSW_9_0_X IBs (tests are also fine). This pull request requires discussion in the ORP meeting before it's merged. @davidlange6, @smuzaffar

@davidlange6
Copy link
Contributor

+1

@cmsbuild cmsbuild merged commit 9eda6f6 into cms-sw:CMSSW_9_0_X Feb 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants