Skip to content

Fix warning C26817 on copying in for (auto vh : value_and_holder(...))#2382

Merged
YannickJadoul merged 2 commits into
pybind:masterfrom
MichaelGoulding:master
Aug 14, 2020
Merged

Fix warning C26817 on copying in for (auto vh : value_and_holder(...))#2382
YannickJadoul merged 2 commits into
pybind:masterfrom
MichaelGoulding:master

Conversation

@MichaelGoulding

@MichaelGoulding MichaelGoulding commented Aug 11, 2020

Copy link
Copy Markdown
Contributor

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).

@YannickJadoul YannickJadoul left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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.

@YannickJadoul YannickJadoul left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good catch, @bstaletic

@YannickJadoul YannickJadoul left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
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