1

Consider this:

struct Man
{
  operator int const&  () const&  { return           m_ban ; }
  operator int      && ()      && { return std::move(m_ban); }
  int m_ban;
};

void ff(int const& ) { std::cerr << "==== void ff(int const& )" << std::endl; }
void ff(int      &&) { std::cerr << "==== void ff(int      &&)" << std::endl; }

And later:

  Man man;
  ff(static_cast<Man const& >(man));
  ff(static_cast<Man      &&>(man));

This perfectly works with gcc-8.3.0, but gcc-9.3.0 and all versions of clang and msvc can't pick the right ff for the second call. Is this a compiler bug? How the code should behave according to the standard?

Indeed, both type operators can be called for Man&&:

  static_cast<Man&&>(man).operator int const& ();
  static_cast<Man&&>(man).operator int      &&();

But because of the ref-qualification, the second one should be picked during the implicit conversion, right?

Vahagn
  • 4,670
  • 9
  • 43
  • 72
  • 1
    May I suggest a slightly simplified version of your formulation: https://godbolt.org/z/p255EN . It took me quite some time to parse your code to see what was important or not. This seems to relate to an actual change in the standard that I don't know of. I'd like to know what happens here – Guillaume Gris Jul 03 '20 at 09:39
  • This code does not compile with -std=c++11 too. Other compilers also reject this with similar error message, so I suspect that gcc 9 fixed some bug introduced in the past. – Daniel Frużyński Jul 03 '20 at 09:58
  • @DanielFrużyński Yes, that is strange! Why that two type conversions should be considered ambiguous alternatives, when one of them has an "obvious" advantage, being ref-qualified with `&&` and the conversion operator being to be called on an rvalue? – Vahagn Jul 03 '20 at 10:11
  • 1
    Looks that this contains answer to your question: https://stackoverflow.com/questions/23377647/explicit-ref-qualified-conversion-operator-templates-in-action – Daniel Frużyński Jul 03 '20 at 10:33
  • @DanielFrużyński Yes, seems so. Thus this is a bug with the standard, ranter than a bug with the compilers. `gcc-8` was doing perfectly well! I am hoping to find some hack option for `gcc-9` that would enable this. – Vahagn Jul 03 '20 at 10:50

0 Answers0