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 warning C26817 on copying in for (auto vh : value_and_holder(...)) #2382

Merged
merged 2 commits into from
Aug 14, 2020

Conversation

MichaelGoulding
Copy link
Contributor

@MichaelGoulding MichaelGoulding commented Aug 11, 2020

C26817: Potentially expensive copy of variable 'vh' in range-for loop. Consider making it a const reference (es.71).

EDIT (@YannickJadoul): Fixes #2379

…nge-for loop. Consider making it a const reference (es.71).
Copy link
Collaborator

@YannickJadoul YannickJadoul left a comment

Choose a reason for hiding this comment

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

value_and_holder shouldn't be too expensive to copy (and quite optimizable, even, I'd think?), but I see no immediate reason why this wouldn't work, so why not! 👍

@YannickJadoul YannickJadoul changed the title Fix warning C26817 Fix warning C26817 on copying in for (auto vh : value_and_holder(...)) Aug 11, 2020
@bstaletic
Copy link
Collaborator

In theory, value_and_holder is big enough to be passed by reference. In practice, gcc and clang seem to output the same assembly.

Besides the auto vh in cast.h, there's also one in detail/class.h. We should fix both.

Copy link
Collaborator

@YannickJadoul YannickJadoul left a comment

Choose a reason for hiding this comment

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

Good catch, @bstaletic

Copy link
Collaborator

@YannickJadoul YannickJadoul left a comment

Choose a reason for hiding this comment

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

I've made those changes and pushed them. Let's see if CI turns nicely green.

@YannickJadoul
Copy link
Collaborator

Green, green, green, green, green, ...

Thanks for reporting and fixing, @MichaelGoulding!

@YannickJadoul YannickJadoul merged commit fb042d6 into pybind:master Aug 14, 2020
@MichaelGoulding
Copy link
Contributor Author

Thanks, for fixing up the last bit. @YannickJadoul

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.

Warning when compiling under Visual Studio 16.7.0
4 participants