Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug fix variable 'actual_iterations' set but not used (#1517) #3

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

Merged
merged 1 commit into from
Jul 26, 2024

Conversation

mike-malburg
Copy link

@mike-malburg mike-malburg commented Jul 26, 2024

Description

Pick bug fix from upstream repo for the this error we keep getting when compiling all of CommonCpp on Mac.

Upstream commit: google@62edc4f

Error

/Volumes/BuildDisk/Azure/_work/6/s/ThirdParty/benchmark/test/options_test.cc:70:10: error: variable 'actual_iterations' set but not used [-Werror,-Wunused-but-set-variable]
  size_t actual_iterations = 0;
         ^
1 error generated.

Original description from upstream commit

* Bug fix variable 'actual_iterations' set but not used

Compiling the project in clang 15 without -Wno-unused-but-set-variable flag the following error is generated:

benchmark-src/test/options_test.cc:70:10: error: variable 'actual_iterations' set but not used [-Werror,-Wunused-but-set-variable]
  size_t actual_iterations = 0;
         ^

* Adjust according formatting of `clang-format`

* Bug fix variable 'actual_iterations' set but not used

Compiling the project in clang 15 without -Wno-unused-but-set-variable flag the following error is generated:

benchmark-src/test/options_test.cc:70:10: error: variable 'actual_iterations' set but not used [-Werror,-Wunused-but-set-variable]
  size_t actual_iterations = 0;
         ^

* Adjust according formatting of `clang-format`

Co-authored-by: dominic hamon <[email protected]>
@mike-malburg mike-malburg self-assigned this Jul 26, 2024
Copy link
Collaborator

@ajorians ajorians left a comment

Choose a reason for hiding this comment

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

OK; seem fine. Though I reckon since we are 2 years old:
image

I wonder if we should just use the official repo. The only reason I have a commit had to do with CSMLTestRunner also linked with Benchmark. Now that is no longer the case I reckon we could use the official repo again.

But oh well; I am OK with these changes 👍 😃

@mike-malburg
Copy link
Author

I wonder if we should just use the official repo.

It definitely needs to be updated soon. I just didn't have time to deal with any fallout of that today.

Thanks for the review!

@mike-malburg mike-malburg merged commit 057c4cc into main Jul 26, 2024
143 of 186 checks passed
@mike-malburg mike-malburg deleted the bug/actual_iterations branch July 26, 2024 19:02
@@ -67,8 +67,8 @@ void BM_explicit_iteration_count(benchmark::State& state) {

// Test that the requested iteration count is respected.
assert(state.max_iterations == 42);
size_t actual_iterations = 0;
for (auto _ : state) ++actual_iterations;
for (auto _ : state) {

Choose a reason for hiding this comment

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

this loop is not doing anything, is it? Is this something we want in the future? If so using a maybe_unused instead of deleting the variable maybe the way to go. Or get rid of this code entirely, given that it is not doing anything.

Copy link
Author

Choose a reason for hiding this comment

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

I agree, that's how they should have fixed it, and it's how I fixed it locally when I first encountered this. I am picking the upstream commit intentionally instead of doing that, though, so that when we update the fork, we won't have a conflict.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am under the assumption that the variable named underscore (_) is iterating over the state collection. Yes the body of the for-loop is empty and thus you may believe it isn't doing anything. But just looping is doing something. Like it is probably something like:

auto it = state.begin();
while( it != state.end() ) it++;

So I do believe it wouldn't make sense to get rid of the for-loop completely as it might actually be doing something.

Hope that helps some 😃

Choose a reason for hiding this comment

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

but unless there is some really weird behavior attached to the operator++ then that loop does not do anything. Maybe the State copy constructor does something really weird as well. Otherwise we are just assigning each element of state to a temporary. Weird 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.

4 participants