https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64611

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to J. van Oosten from comment #0)
> Basically, it's applying the friend operator << function on the internal
> std::ostringstream object, while I would expect the compiler to pick
> 'std::ostringstream::operator <<()'. Furthermore, casting, using ::
> resolution operators, using the 'using' word all does not work.

This works fine:

    template <typename F> friend F &operator << (F &in, float f) 
    {
        in.type ("f");
        using std::operator<<;
        in.m_buf << f;          // This causes a 'recursive' compile call
        return in;
    }


Reduced test that clang and EDG compile OK:

namespace std
{
  struct ostream { };
  struct ostringstream : ostream { };

  ostream& operator<<(ostream&, float);
}

struct SmartStream
{
    template <typename F> friend F &operator << (F &in, float f) 
    {
        in.m_buf << f;          // This causes a 'recursive' compile call
        return in;
    }

    std::ostringstream m_buf;
};

int main()
{
    SmartStream ss;
    ss << 123.456;
}

Reply via email to