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: clang warnings. #508

Merged
merged 1 commit into from
Nov 22, 2022
Merged

fix: clang warnings. #508

merged 1 commit into from
Nov 22, 2022

Conversation

romange
Copy link
Collaborator

@romange romange commented Nov 22, 2022

Signed-off-by: Roman Gershman [email protected]

Signed-off-by: Roman Gershman <[email protected]>
@romange romange requested a review from dranikpg November 22, 2022 05:56
@@ -428,7 +428,7 @@ error_code Replica::InitiateDflySync() {
auto partition = Partition(num_df_flows_);
shard_set->pool()->AwaitFiberOnAll([&](unsigned index, auto*) {
for (auto id : partition[index]) {
if (ec = shard_flows_[id]->StartFullSyncFlow(&sb))
if ((ec = shard_flows_[id]->StartFullSyncFlow(&sb)))
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe the new still "if" with "if (ec = shard_flows_[id]->StartFullSyncFlow(&sb); ec) {..} would be more readable? right now this look a little bit like a classic C bug where you're assign and then git the side effect from assignment.

@@ -871,7 +871,7 @@ error_code ServerFamily::DoSave(bool new_version, Transaction* trans, string* er
const auto scripts = script_mgr_->GetLuaScripts();
auto& summary_snapshot = snapshots[shard_set->size()];
summary_snapshot.reset(new RdbSnapshot(fq_threadpool_.get()));
if (ec = DoPartialSave(filename, path, start, scripts, summary_snapshot.get(), nullptr)) {
if ((ec = DoPartialSave(filename, path, start, scripts, summary_snapshot.get(), nullptr))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as the previous comment - I think that it would look more like the intent is to assign then check. assign with side effect is the classic that you;re not sure if this is a bug or you're using the side effect

@@ -880,7 +880,7 @@ error_code ServerFamily::DoSave(bool new_version, Transaction* trans, string* er
auto cb = [&](Transaction* t, EngineShard* shard) {
auto& snapshot = snapshots[shard->shard_id()];
snapshot.reset(new RdbSnapshot(fq_threadpool_.get()));
if (ec = DoPartialSave(filename, path, start, {}, snapshot.get(), shard)) {
if ((ec = DoPartialSave(filename, path, start, {}, snapshot.get(), shard))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same issue as with above

@dranikpg
Copy link
Contributor

dranikpg commented Nov 22, 2022

For some reason I thought the new If-with-initializer is c++20, so I avoided it. We should use it of course.

Note that the code is even worse than you think it is 😁

AggregateValue's assignment operator returns the value of the argument. So it equivalent to the following. This is because we need to know if DoPartialSave started something or not, and we care less about the global error, but need to assign it afterwards.

if (auto local_ec = DoPartialSave; local_ec) {
  ec = local_ec
}

@romange
Copy link
Collaborator Author

romange commented Nov 22, 2022

looks weird. Frankly, I prefer avoiding using assignments in if statements at all, but this PR is about fixing warnings.
I did not want to raise style argument here. but we can discuss this stuff during our next end meeting

@dranikpg
Copy link
Contributor

dranikpg commented Nov 22, 2022

I can fix the AggregateValue-if issue separately

@romange
Copy link
Collaborator Author

romange commented Nov 22, 2022

I will submit it anyway to save the hop. Feel free to change when you touch that code :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants