From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 96670 invoked by alias); 23 Apr 2015 14:43:47 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 96233 invoked by uid 48); 23 Apr 2015 14:43:43 -0000 From: "howarth.at.gcc at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/65861] New: libstdc++ is silently generating wrong code when its std::search is given an input iterator Date: Thu, 23 Apr 2015 14:43:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 5.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: howarth.at.gcc at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-04/txt/msg02029.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65861 Bug ID: 65861 Summary: libstdc++ is silently generating wrong code when its std::search is given an input iterator Product: gcc Version: 5.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: howarth.at.gcc at gmail dot com While porting rstudio 0.98.1103 to build under clang/libc++, I uncovered a defect in the libstdc++ handling of input iterators by std::search (https://llvm.org/bugs/show_bug.cgi?id=23307). The reduced test case is silently generating wrong code when its std::search is given an input iterator (it assumes it can save the iterator position and backtrack). #include #include #include void f(std::istream &s, std::string x) { std::istreambuf_iterator eod; std::search(std::istreambuf_iterator(s), eod, x.begin(), x.end()); } Clang with libc++ properly rejects this with the error... In file included from test3.cpp:1: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:439: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:628: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:604: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iterator:849:22: error: implicit instantiation of undefined template 'std::__1::basic_istream >' : __sbuf_(__s.rdbuf()) {} ^ test3.cpp:6:19: note: in instantiation of member function 'std::__1::istreambuf_iterator >::istreambuf_iterator' requested here std::search(std::istreambuf_iterator(s), ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iosfwd:109:33: note: template is declared here class _LIBCPP_TYPE_VIS_ONLY basic_istream; ^ In file included from test3.cpp:1: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:439: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:1572:12: error: no matching function for call to '__search' return _VSTD::__search::type> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:358:15: note: expanded from macro '_VSTD' #define _VSTD std::_LIBCPP_NAMESPACE ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:1586:19: note: in instantiation of function template specialization 'std::__1::search >, std::__1::__wrap_iter, std::__1::__equal_to >' requested here return _VSTD::search(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); ^ test3.cpp:6:12: note: in instantiation of function template specialization 'std::__1::search >, std::__1::__wrap_iter >' requested here std::search(std::istreambuf_iterator(s), ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:1456:1: note: candidate function [with _BinaryPredicate = std::__1::__equal_to &, _RandomAccessIterator1 = std::__1::istreambuf_iterator >, _RandomAccessIterator2 = std::__1::__wrap_iter] not viable: no known conversion from 'typename std::iterator_traits > >::iterator_category' (aka 'std::__1::input_iterator_tag') to 'std::__1::random_access_iterator_tag' for 6th argument __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:1419:1: note: candidate function [with _BinaryPredicate = std::__1::__equal_to &, _ForwardIterator1 = std::__1::istreambuf_iterator >, _ForwardIterator2 = std::__1::__wrap_iter] not viable: no known conversion from 'typename std::iterator_traits > >::iterator_category' (aka 'std::__1::input_iterator_tag') to 'std::__1::forward_iterator_tag' for 6th argument __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, ^ 2 errors generated.