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

[small_map] Use hidden friends for operator==/!= #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Quuxplusone
Copy link

clang -std=c++2b complains about the old way:

./src/base/small_map.h:555:40: warning: all paths through
this function will call itself [-Winfinite-recursion]
    const const_iterator& other) const {
                                       ^

There are two pieces to the "right" solution: First, use the hidden
friend idiom to make sure all our operator==s are symmetrical and
don't treat the first argument differently from the second. Second,
eliminate the heterogeneous comparison operators; just rely
on the existing implicit conversion from iterator to const_iterator
to do the right thing.

`clang -std=c++2b` complains about the old way:

    ./src/base/small_map.h:555:40: warning: all paths through
    this function will call itself [-Winfinite-recursion]
        const const_iterator& other) const {
                                           ^

There are two pieces to the "right" solution: First, use the hidden
friend idiom to make sure all our operator==s are symmetrical and
don't treat the first argument differently from the second. Second,
eliminate the heterogeneous comparison operators; just rely
on the existing implicit conversion from `iterator` to `const_iterator`
to do the right thing.
@Quuxplusone
Copy link
Author

@OlafvdSpek ping!

@OlafvdSpek
Copy link
Owner

Pong!
Looks good to me.
Is the infinite recursion hit in practice though?

@Quuxplusone
Copy link
Author

Is the infinite recursion hit in practice though?

Yes, certainly if the offending operator!= is ever actually called, it'll infinite-recurse. I don't know whether it's ever actually called anywhere within ctemplate, and I also don't know whether it's possible for the client-of-ctemplate to call it directly. But I can at least confirm that it's located somewhere visible enough to break the build of the client-of-ctemplate when they try to compile the header in C++20 mode. So it's probably also reachable at runtime somehow. (Otherwise, you should just delete the whole function as unreachable!)

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.

2 participants