mattkretz / wg21-papers

my papers to WG21 — the C++ committee
5 stars 7 forks source link

non-member operator[]: Explore consequences from ADL and indirectly incomplete types #81

Open mattkretz opened 3 years ago

mattkretz commented 3 years ago

Similar issues exist and operator[] would be no exception:

class Incomplete;

template <typename T>
  class Wrap { T x; };

void f(const std::vector<Wrap<Incomplete>*>& data) {
  data[0];
}

This compiles today since the pointer returned from data[0] does not require a complete type. However, once non-member operator[] is possible, the compiler has to look into Wrap<Incomplete>, whether it has a hidden friend operator[] which is a better match than the one from std::vector. While instantiating Wrap<Incomplete>, T x leads to an error, making the above example ill-formed.