Author: rogfer01
Date: Mon Dec 11 05:54:58 2017
New Revision: 320363

URL: http://llvm.org/viewvc/llvm-project?rev=320363&view=rev
Log:
[libcxx] Define istream_iterator equality comparison operators out-of-line

Currently libc++ defines operator== and operator!= as friend functions in the
definition of the istream_iterator class template. Such definition has a subtle
difference from an out-of-line definition required by the C++ Standard: these
functions can only be found by argument-dependent lookup, but not by qualified
lookup.

This patch changes the definition, so that it conforms to the C++ Standard and
adds a check involving qualified lookup to the test suite.

Patch contributed by Mikhail Maltsev.

Differential Revision: https://reviews.llvm.org/D40415


Modified:
    libcxx/trunk/include/iterator
    
libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/istream.iterator.ops/equal.pass.cpp

Modified: libcxx/trunk/include/iterator
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/iterator?rev=320363&r1=320362&r2=320363&view=diff
==============================================================================
--- libcxx/trunk/include/iterator (original)
+++ libcxx/trunk/include/iterator Mon Dec 11 05:54:58 2017
@@ -904,15 +904,37 @@ public:
     _LIBCPP_INLINE_VISIBILITY istream_iterator  operator++(int)
         {istream_iterator __t(*this); ++(*this); return __t;}
 
+    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
     friend _LIBCPP_INLINE_VISIBILITY
-    bool operator==(const istream_iterator& __x, const istream_iterator& __y)
-        {return __x.__in_stream_ == __y.__in_stream_;}
+    bool
+    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
+               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
 
+    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
     friend _LIBCPP_INLINE_VISIBILITY
-    bool operator!=(const istream_iterator& __x, const istream_iterator& __y)
-        {return !(__x == __y);}
+    bool
+    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
+               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
 };
 
+template <class _Tp, class _CharT, class _Traits, class _Distance>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
+           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
+{
+    return __x.__in_stream_ == __y.__in_stream_;
+}
+
+template <class _Tp, class _CharT, class _Traits, class _Distance>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
+           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
+{
+    return !(__x == __y);
+}
+
 template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
 class _LIBCPP_TEMPLATE_VIS ostream_iterator
     : public iterator<output_iterator_tag, void, void, void, void>

Modified: 
libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/istream.iterator.ops/equal.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/istream.iterator.ops/equal.pass.cpp?rev=320363&r1=320362&r2=320363&view=diff
==============================================================================
--- 
libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/istream.iterator.ops/equal.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/iterators/stream.iterators/istream.iterator/istream.iterator.ops/equal.pass.cpp
 Mon Dec 11 05:54:58 2017
@@ -49,4 +49,7 @@ int main()
 
     assert(i4 == i4);
     assert(i4 == i5);
+
+    assert(std::operator==(i1, i2));
+    assert(std::operator!=(i1, i3));
 }


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to