-
Notifications
You must be signed in to change notification settings - Fork 1.4k
C++17 fixes #591
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
C++17 fixes #591
Conversation
std::apply is part of C++17 standard. The order of argument was wrong. According to the documention it's function first followed by the tuple. Signed-off-by: David Abdurachmanov <[email protected]>
This allows to have a consistent __cplusplus value between GCC 7.1.1 and what's being executed in ROOT interpreter. This is basically a backport from upstream: - llvm-mirror/clang@65ecf3a - r298299 in SVN Signed-off-by: David Abdurachmanov <[email protected]>
std::apply is part of C++17. Thus if we are compiling ROOT6 with GCC 7.1.1 in C++17 mode we don't need std::__ROOT::apply otherwise it would generate ambiguity errors. Signed-off-by: David Abdurachmanov <[email protected]>
We use std::function which is defined in <functional> header. Signed-off-by: David Abdurachmanov <[email protected]>
- to_string() is not part of std::string_view in C++17; - use data() to access const raw string data. Signed-off-by: David Abdurachmanov <[email protected]>
Signed-off-by: David Abdurachmanov <[email protected]>
|
Can one of the admins verify this patch? |
| // C++ translation unit. | ||
| if (LangOpts.CPlusPlus1z) | ||
| Builder.defineMacro("__cplusplus", "201406L"); | ||
| Builder.defineMacro("__cplusplus", "201703L"); |
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.
Don't we need to match clang value?
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.
There is no real need. The compiler will not care as it's not using this value. Clang 3.9 which is embedded in ROOT already supported majority of C++17 features. Changing __cplusplus to a proper value does not mean that C++17 is out experimental land. This is basically for people who use __cplusplus to figure out what C++ features they want to use.
io/io/v7/src/TFile.cxx
Outdated
|
|
||
| void WriteMemoryWithType(std::string_view name, const void* address, TClass* cl) final { | ||
| fOldFile->WriteObjectAny(address, cl, name.to_string().c_str()); | ||
| fOldFile->WriteObjectAny(address, cl, name.data()); |
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.
Isn't data() not guaranteed to be null terminated? (which WriteObjectAny requires)?
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.
You are right. Starting C++11 std::string .data() and .c_str() both provide null-terminated result, but the same does not apply to std::string_view. The example I am looking even shows that one needs to create a temporary string and then call .data().
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.
Could you point me to the comment in the code which states that it's required? At first look I don't see it explicitly mentioned in TBufferFile::WriteObjectClass or TBufferFile::WriteObjectAny and I didn't see any breakage in CMSSW.
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.
Ops, it should be TDirectoryFile::WriteObjectAny, but same story. No comments mention that it should be null-terminated. Even provided example is not null-terminated.
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.
Starting C++11 std::string .data() and .c_str() both provide null-terminated result
I somehow did not catch that. Thanks!
Could you point me to the comment in the code which states that it's required?
Humm ... WriteObjectAny takes a const char* and use it as null terminated string, I am not sure why there would be a 'special' comment in this routine to make that explicit ...
It is clear that std::string_view::data is not appropriate here, as this returns the first characters of the view, which could for example be a sub-part of a larger string.
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.
Weekend already. I was looking at completely different argument :)
io/io/v7/src/TFile.cxx
Outdated
|
|
||
| std::string ret = ::TFile::GetCacheFileDir(); | ||
| ::TFile::SetCacheFileDir(path.to_string().c_str()); | ||
| ::TFile::SetCacheFileDir(path.data()); |
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.
Don't we need a null terminated string here?
Alternatively, what about adding a string_view overload of ::TFile::SetCacheFileDir ?
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.
Yeah, we could do that.
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.
At the end I didn't like idea of overload. It would cause more lines to be changed at this point and wouldn't work with TString (ambiguity). Let's do more minimal change for now.
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.
Actually, we don't need an overload just a replacement as a string_view can be constructed implicitly from a const char*. I uploaded the change in signature of TFile::SetCacheFileDir.
std::string_view::data() does not guarantee null-terminated string. Signed-off-by: David Abdurachmanov <[email protected]>
|
@pcanal what else do we need to do for this PR? I probably need to change lines to |
Yes, please :) |
|
I merged the non-string_view changes in the master and 6.10. Reviewing the string_view changes made us rethink whether string_view ought to be used here ... |
|
I am looking into this PR, but ROOT doesn't compile anymore in C++17 after LLVM update (I think, I found why -- testing). The patch to change cplusplus is no more needed as exact same thing is already in newer integrated LLVM. |
| #define ROOT7_THistImpl | ||
|
|
||
| #include <cctype> | ||
| #include <functional> |
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.
Thanks, David!
|
Just to summarize, the following still needs to be resolved: |
|
@davidlt Could you please rebase and push so that we can test against latest master? Thanks! |
|
@amadio to my understanding there is no resolution how to resolve it. See a comment from @pcanal #591 (comment) Thus currently this PR acts as a reminder/todo. |
|
@davidlt I have changes to remove usage of string view from ROOT7's TFile in C++17 mode, but I wanted to check the status of this PR before merging them in. If you could remove your changes that were merged by Philippe and keep the rest, I can take a look and cherry-picking your fixes into master as needed. |
|
Based on this PR the only thing what's left is TFile changes (unless new breakage was introduced). The rest is already in to my knowledge. Thus you if you merge TFile changes you can close this one. |
|
Alright, I guess I will merge my changes and close this then. Thanks! |
I have moved CMSSW to the latest GCC 7.1.1 and to the tip of 6.10 patches branch. These are the fixes I have applied on top of that branch for CMS.