facebook / folly

An open-source C++ library developed and used at Facebook.
https://groups.google.com/forum/?fromgroups#!forum/facebook-folly
Apache License 2.0
28.5k stars 5.57k forks source link

clang warning in F14 with C++20 #1536

Open tudor opened 3 years ago

tudor commented 3 years ago
ISO C++20 considers use of overloaded operator '!=' (with operand types 'folly::f14::detail::VectorContainerIterator<std::pair<const std::basic_string<char>, rockset::NodeInfo> *>' and 'folly::f14::detail::F14BasicMap<folly::f14::detail::VectorContainerPolicy<std::basic_string<char>, rockset::NodeInfo, folly::transparent<folly::hasher<folly::Range<const char *>>>, folly::transparent<std::equal_to<folly::Range<const char *>>>, void, std::integral_constant<bool, true>>>::iterator' (aka 'folly::f14::detail::VectorContainerIterator<std::pair<const std::basic_string<char>, rockset::NodeInfo> *>')) to be ambiguous despite there being a unique best viable function with non-reversed arguments(-Wambiguous-reversed-operator)
F14Policy.h(942, 8): Candidate function with non-reversed arguments
F14Policy.h(939, 8): Ambiguous candidate function with reversed arguments

version of the code where the line numbers are correct: https://github.com/facebook/folly/blame/e741d8efa0052df83c187331745dd4441c693fcb/folly/container/detail/F14Policy.h#L939

I suspect that this is because C++20 now adds more operators to the candidate set, and they all have to go through the VectorContainerIterator<ValuePtr> -> VectorContainerIterator<ValueConstPtr> conversion, which makes them ambiguous, in a way similar to https://stackoverflow.com/questions/60568088/breaking-change-in-c20-or-regression-in-clang-trunk-gcc-trunk-when-overloading

tudor commented 3 years ago

The calling code is

    auto it = nodes_.find(nodeId);
    if (it != nodes_.end()) {
        return it->second;
    }

in a non-const method, so nodes_ is a non-const reference to F14FastMap<string, NodeInfo, folly::transparent<folly::hasher<folly::StringPiece>>, folly::transparent<std::equal_to<folly::StringPiece>>>