[LLVMbugs] [Bug 19425] New: ostream_iterator::operator* is not constant

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Apr 14 05:08:57 PDT 2014


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: unassignedclangbugs at nondot.org
          Reporter: root at zta.lk
                CC: llvmbugs at cs.uiuc.edu, mclow.lists at gmail.com
    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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140414/9eb46f1e/attachment.html>


More information about the llvm-bugs mailing list