Skip to content

Wrap local vars in std::move (Clang 7 build fix) #3239

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

Conversation

karkhaz
Copy link
Collaborator

@karkhaz karkhaz commented Oct 28, 2018

This commit fixes #3238, a warning emitted by clang 7.0:

java_bytecode_convert_method.cpp:2924:10: error: local variable
'block' will be copied despite being returned by name
[-Werror,-Wreturn-std-move]
  return block;
         ^~~~~
java_bytecode_convert_method.cpp:2924:10: note: call 'std::move'
explicitly to avoid copying
  return block;
         ^~~~~
         std::move(block)

The fix is to wrap all such returned local variables in a call to
std::move().

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

This commit fixes diffblue#3238, a warning emitted by clang 7.0:

```
java_bytecode_convert_method.cpp:2924:10: error: local variable
'block' will be copied despite being returned by name
[-Werror,-Wreturn-std-move]
  return block;
         ^~~~~
java_bytecode_convert_method.cpp:2924:10: note: call 'std::move'
explicitly to avoid copying
  return block;
         ^~~~~
         std::move(block)
```

The fix is to wrap all such returned local variables in a call to
std::move().
@smowton
Copy link
Contributor

smowton commented Oct 28, 2018

Did you arrive at this particular list of return sites by a regex or similar match, or is this exactly equal to the places where Clang 7 complains?

@karkhaz
Copy link
Collaborator Author

karkhaz commented Oct 28, 2018

It is exactly equal to the places where Clang 7 complains. I don't think a simple regex could deal with this, it's context-sensitive, the variables need to be local.

@smowton
Copy link
Contributor

smowton commented Oct 28, 2018

Great -- it sounds like we're not adding this in cases where return-value optimisation would apply in that case.

@karkhaz
Copy link
Collaborator Author

karkhaz commented Oct 28, 2018

Yes, this is a pretty cool warning. I'm not sure who is in charge of the CI, but perhaps it's worth adding Clang 7 at some point? I don't mind posting PRs for any more of these that people introduce in the meantime, if nobody else is using Clang 7 yet, but it might be worth doing at some point.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

Passed Diffblue compatibility checks (cbmc commit: 72bfc35).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/89432202

@kroening kroening merged commit 70b98fe into diffblue:develop Oct 28, 2018
@karkhaz karkhaz deleted the kk-bugfix-clang-7-Wreturn-std-move branch October 28, 2018 20:44
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.

Build fails with Clang 7.0 due to local variable copies
6 participants