Issue Details (XML | Word | Printable)

Key: STDCXX-321
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Martin Sebor
Reporter: Martin Sebor
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
C++ Standard Library

error on std::operator==(istream_iterator, istream_iterator)

Created: 19/Jan/07 02:31 AM   Updated: 17/Apr/08 10:39 AM
Return to search
Component/s: 24. Iterators
Affects Version/s: 4.1.2, 4.1.3, 4.1.4, 4.2.0
Fix Version/s: 4.2.1

Time Tracking:
Original Estimate: 4h
Original Estimate - 4h
Remaining Estimate: 0.5h
Time Spent - 3.5h Remaining Estimate - 0.5h
Time Spent: 3.5h
Time Spent - 3.5h Remaining Estimate - 0.5h

Environment: All
Issue Links:
Dependants
 

Severity: Compiler Error
Resolution Date: 06/Feb/08 06:59 PM


 Description  « Hide
The well-formed program below fails to compile with both EDG eccp 3.8 and gcc 4.1.0 (I didn't try others but it's likely a bug in the library)
$ cat t.cpp && make t
#include <iterator>

int main ()
{
    std::istream_iterator<char, char> i;
    (void)(i == i);
}
eccp -c -I/build/sebor/dev/stdlib/include/ansi -D_RWSTDDEBUG    -D_RWSTD_USE_CONFIG -I/build/sebor/dev/stdlib/include -I/build/sebor/eccp-3.8-11s/include -I/build/sebor/dev/stdlib/include/ansi -I/build/sebor/PlumHall/lvs06a/conform -I/build/sebor/PlumHall/lvs06a/dst.3  -A -x --template_directory=/build/sebor/eccp-3.8-11s/lib -g  --display_error_number --remarks --diag_suppress 193,236,340,401,261,479,487,678,679,815 --diag_suppress 177,381,191,68,550,611,997,549   t.cpp
"/build/sebor/dev/stdlib/include/rw/_streamiter.h", line 124: error #349: no
          operator "!" matches these operands
            operand types are: ! std::basic_istream<char,
                      std::char_traits<char>>
      return (__x._C_strm && !!*__x._C_strm) == (__y._C_strm && !!*__y._C_strm);
                              ^
          detected during instantiation of "bool std::operator==(const
                    std::istream_iterator<_TypeT, _CharT, _Traits, _Distance>
                    &, const std::istream_iterator<_TypeT, _CharT, _Traits,
                    _Distance> &) [with _TypeT=char, _CharT=char,
                    _Traits=std::char_traits<char>, _Distance=int]" at line 6
                    of "t.cpp"

"/build/sebor/dev/stdlib/include/rw/_streamiter.h", line 124: error #349: no
          operator "!" matches these operands
            operand types are: ! std::basic_istream<char,
                      std::char_traits<char>>
      return (__x._C_strm && !!*__x._C_strm) == (__y._C_strm && !!*__y._C_strm);
                                                                 ^
          detected during instantiation of "bool std::operator==(const
                    std::istream_iterator<_TypeT, _CharT, _Traits, _Distance>
                    &, const std::istream_iterator<_TypeT, _CharT, _Traits,
                    _Distance> &) [with _TypeT=char, _CharT=char,
                    _Traits=std::char_traits<char>, _Distance=int]" at line 6
                    of "t.cpp"

2 errors detected in the compilation of "t.cpp".
make: *** [t.o] Error 2


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Martin Sebor added a comment - 29/Aug/07 09:54 PM
Scheduled for 4.2.1.

Martin Sebor added a comment - 31/Oct/07 11:52 PM
This affects all released versions.

Farid Zaripov added a comment - 16/Nov/07 05:43 PM
The problem is that operator==(istream_iterator<>&, istream_iterator<>&) calls basic_istream::operator!(), but basic_istream::operator!() is defined in <istream> header file.

So <istream> should be included in rw/_streamiter.h.

The similar problem in STDCXX-375.


Martin Sebor added a comment - 19/Nov/07 05:54 AM
I'm not sure #including all of <istream> in <iterator> is a good idea. But see STDCXX-645.

Farid Zaripov added a comment - 01/Feb/08 09:37 AM
We could change the operator==(istream_iterator<>&, istream_iterator<>&) to just compare the pointers _C_strm, but anyway the basic_istream::operator!(), is used in istream_iterator::operator++() and the following example also would fail:
#include <iterator>

int main ()
{
    std::istream_iterator<char, char> i;
    ++i;
    i++;
}

Farid Zaripov added a comment - 01/Feb/08 09:51 AM
The Dinkumware STL doesn't #includes <istream> in <iterator> and the example with incrementing of the iterator is also fail to compile (the example with operator==() doesn't fail because operator==() implementation compares the pointers only).

The STLport #includes basic_istream definitions before definitions of the istream_iterator.
The SGI STL from gcc also #includes <istream> in <iterator>.


Martin Sebor added a comment - 01/Feb/08 05:05 PM
Disabled formatting.

Martin Sebor added a comment - 01/Feb/08 05:11 PM
I've been working on STDCXX-645 and I expect to have a solution for the equality operator. I don't think your test case with the increment operator is solvable without #including <istream> in <iterator> which we probably don't want to do because of all the baggage that <istream> brings in with it (locale, string, etc.)

Fundamentally, this is LWG issue 343.


Martin Sebor added a comment - 06/Feb/08 04:56 PM
Reassigning to self since this depends on STDCXX-645 that I've been working on.

Martin Sebor added a comment - 06/Feb/08 06:58 PM
The original issue has been fixed – see the patch committed in r618883 for STDCXX-645.
The original test case has been committed to our regression test suite in r619099.

The test case from Farid's comment above still doesn't compile but since that one has undefined behavior I'm not concerned.


Martin Sebor added a comment - 06/Feb/08 06:59 PM
Closing as fixed.

Farid Zaripov added a comment - 17/Apr/08 10:39 AM