This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: another effc++ spurious warning?
- From: "Giovanni Bajo" <giovannibajo at libero dot it>
- To: "Paolo Carlini" <pcarlini at suse dot de>
- Cc: "Benjamin Kosnik" <bkoz at redhat dot com>,<libstdc++ at gcc dot gnu dot org>
- Date: Thu, 8 Jul 2004 15:20:30 +0200
- Subject: Re: another effc++ spurious warning?
- References: <066601c464e7$26741020$a54a2597@bagio> <40ED4313.703@suse.de>
Paolo Carlini wrote:
> The relevant item is 24.5.4.2, p4: according to it "[operator++(int)]
> Returns: *this."
>
> Therefore, I cannot see anything wrong with our implementation:
>
> /// Return *this.
> ostreambuf_iterator&
> operator++(int)
> { return *this; }
Hi Paolo, there is nothing wrong here of course. The rule of the thumb rule
spotted by -Weffc++ is that a postfix operator++ should return a temporary copy
of the original object before its increment, so you cannot do that sanely if
you return a reference. Think of "(a++)++".
Of course, this does not make sense in the case of input/output iterators,
because a "copy" does not respect the usual copy semantic. I am not sure how we
can tackle this for -Weffc++. Maybe Benjamin was planning to turn off this
specific warning while compiling v3, but there is still a problem when
including the header in user code.
If there are no ideas about how to make the warning smarter, maybe it is better
to disable this very check
Giovanni Bajo