http://llvm.org/bugs/show_bug.cgi?id=19425

            Bug ID: 19425
           Summary: ostream_iterator::operator* is not constant
           Product: libc++
           Version: 3.4
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified

There is a trick used in ostream_iterator, that doesn't quite conform to
standard.

ostream_iterator<T>::operator* returns itself instead of something with
operator=(const T &);

It's almost never an issue since the all the stl algorithms do * and ++ at the
same time. But if we separate * and ++ the way that is shown below, the program
won't compile.

---------
#include <iostream>
#include <iterator>

using namespace std;

void write_5(const ostream_iterator<int> &i)
{
    *i = 5;
}

int main()
{
    ostream_iterator<int> i(cout);
    write_5(i);
    ++i;
}
---------

I believe ostream_iterato<T>::operator* must be defined as const and return a
temporary object, that holds the reference to the stream and have operator=
that do the job. In any case, the code above conforms to standard and doesn't
compile.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to