This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/64611] Using a << operator inside an overloaded << operator gives compile error
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 15 Jan 2015 10:36:53 +0000
- Subject: [Bug c++/64611] Using a << operator inside an overloaded << operator gives compile error
- Auto-submitted: auto-generated
- References: <bug-64611-4 at http dot gcc dot gnu dot org/bugzilla/>
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;
}