-
Notifications
You must be signed in to change notification settings - Fork 89
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
[WIP] Test clang-tidy with selected checks #35
Conversation
…-string-compare,misc-uniqueptr-reset-release,modernize-deprecated-headers,modernize-make-shared,modernize-use-bool-literals,modernize-use-equals-delete,modernize-use-nullptr,modernize-use-override,performance-unnecessary-copy-initialization,readability-container-size-empty,readability-redundant-string-cstr,readability-static-definition-in-anonymous-namespace,readability-uniqueptr-delete-release'
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.
It looks to me like the only changes are:
- replacing
virtual
withoverride
(good: I didn't know about that one, but it's C++11 and I prefer it) container.size() == 0
withcontainer.empty()
(fine: I should have known about that, as it's not a new thing, but okay)- using
make_shared
: I thought I couldn't use it, thinking that it's a C++14 thing, but I was wrong. It's defined in C++11.
I also added a note about json.h because looking over these changes reminded me that I'll need to hide the dependency on RapidJSON headers. (With them included in the .h file, dependent libraries like Josh's are forced to find and include the RapidJSON headers as well. If it were only used in the .cpp file, then they would get the functionality without having to find the includes. We use visibility=hidden
, so there shouldn't be an issue with conflicting symbols, if he happened to include his own different version of RapidJSON.)
I'm in favor of these changes, the best one being virtual
→ override
. However, there are so many that I think we should coordinate when they get applied: I should merge my PR, then we run clang-tidy, then merge that. My current PR has so many changes that it would be difficult to merge this in.
In fact, I'll try making these three changes manually to my branch. Then when we apply clang-tidy on top of it, it will be easier to see if there are other changes it's trying to make that are hidden by the noise that these are making.
@@ -52,7 +53,7 @@ namespace awkward { | |||
size_t cols = (size_t)numfields(); | |||
std::shared_ptr<RecordArray::ReverseLookup> keys = array_.reverselookup(); | |||
if (istuple()) { | |||
keys = std::shared_ptr<RecordArray::ReverseLookup>(new RecordArray::ReverseLookup); | |||
keys = std::make_shared<RecordArray::ReverseLookup>(); | |||
for (size_t j = 0; j < cols; j++) { |
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 make_shared
a C++14 thing?
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.
I was wrong! This is "since C++11". I guess I should have been using this, so that there are fewer dangerous-looking new
keywords around.
bool haskey(const std::string& key) const override; | ||
const std::vector<std::string> keyaliases(int64_t fieldindex) const override; | ||
const std::vector<std::string> keyaliases(const std::string& key) const override; | ||
const std::vector<std::string> keys() const override; |
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.
Replacing virtual
with override
: okay. I didn't know about that, but it provides some additional safety.
@@ -163,7 +163,7 @@ namespace awkward { | |||
} | |||
|
|||
const std::shared_ptr<SliceItem> Slice::head() const { | |||
if (items_.size() != 0) { | |||
if (!items_.empty()) { |
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.
I guess the intent here is more specific, so this is good.
virtual void beginrecord() { writer_.StartObject(); } | ||
virtual void field(const char* x) { writer_.Key(x); } | ||
virtual void endrecord() { writer_.EndObject(); } | ||
void null() override { writer_.Null(); } |
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.
It's not visible in this snippet, but this file leaks a dependence on the RapidJSON headers that I'll need to hide in the .cpp file. I think that can be done by defining these ToJson
classes without implementations in the header and moving all of the implementations to the .cpp file, but that's something that would have to be done manually.
ok, I'm closing this PR for now. |
reopen to add clang-tidy fixes with a readability-redundant-smartptr-get check: |
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, if we could have the opposite of this, to force the inclusion of .get()
, I'd prefer that. I was trying to be conscious of the difference between smart pointers and raw pointers everywhere.
automated fixes with readability-avoid-const-params-in-decls check remove const in places where it could be a reference:
https://clang.llvm.org/extra/clang-tidy/checks/readability-avoid-const-params-in-decls.html |
In the above example, I'm going to want to make sure that it says const std::string tostring_part(const std::string& indent, const std::string& pre, const std::string& post) const; I just haven't been diligent about making sure that all such cases are explicit. Most of the function arguments are either simple numbers, which should be passed by value, or unmodified structures, which should be pass-by-const-reference. It's very rare that I'll want to copy a structure into the function (as the mistaken case above) or pass a non-const reference for remote modification (though there are a few cases, but I think they're numbers). |
int64_t numer = abs(start - stop); | ||
int64_t denom = abs(step); | ||
int64_t numer = std::abs(start - stop); | ||
int64_t denom = std::abs(step); |
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.
This is good. I like this.
My last four commits to PR #33 applied the corrections that clang-tidy wants to make, but manually with much testing to make sure that it agrees with my intentions. If you run clang-tidy over that, we should see what residual changes it wants to make with much less noise. This is not including the removal of |
Thanks, @jpivarski ! I'll do it tomorrow. I've been checking other clang-tidy checks. The good news is that most of them come clean. There are two we may want to look closely: modernize-pass-by-value (https://clang.llvm.org/extra/clang-tidy/checks/modernize-pass-by-value.html) and readability-avoid-const-params-in-decls |
Apply fixes from clang-tidy with -checks='-*,
boost-use-to-string,
misc-string-compare,
misc-uniqueptr-reset-release,
modernize-deprecated-headers,
modernize-make-shared,
modernize-use-bool-literals,
modernize-use-equals-delete,
modernize-use-nullptr,
modernize-use-override,
performance-unnecessary-copy-initialization,
readability-container-size-empty,
readability-redundant-string-cstr,
readability-static-definition-in-anonymous-namespace,
readability-uniqueptr-delete-release'
https://clang.llvm.org/extra/clang-tidy/
@jpivarski - please, review and comment