[PATCH] D144583: [ADT] Fix definition of `adl_begin`/`adl_end` and `Iter`/`ValueOfRange`

Markus Böck via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 27 04:02:26 PST 2023


zero9178 accepted this revision.
zero9178 added a comment.
This revision is now accepted and ready to land.

In D144583#4145846 <https://reviews.llvm.org/D144583#4145846>, @kuhar wrote:

> Edit: I think this boils down to trailing return types participating in SFINE and not wanting to emit hard errors when none of the available `begin` functions matches when `adl_begin` is used within a template argument.

I can see the issue as well. During overload resolution, instantiations of `ValueOfRange` would otherwise immediately error, instead of being a substitution error. This is best seen in `llvm::interleave`:
Instantiating it with a container leads to it calling `interleave(c.begin(), c.end(), ...)` aka with iterators. This once again tries to find the right `interleave` overload and when considering:

  template <typename Container, typename UnaryFunctor, typename StreamT,
            typename T = detail::ValueOfRange<Container>>
  inline void interleave(const Container &c, StreamT &os, UnaryFunctor each_fn,
                         const StringRef &separator)

it actually errors out during substitution of `ValueOfRange` instead of being failing the substitution and removing the candidate from the overload set.

It seems the C++ standard also specifies `std::begin` and friends with the trailing return type, possibly for the same reason.

In that sense LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144583/new/

https://reviews.llvm.org/D144583



More information about the llvm-commits mailing list