another effc++ spurious warning?

Giovanni Bajo giovannibajo@libero.it
Thu Jul 8 13:20:00 GMT 2004


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




More information about the Libstdc++ mailing list