public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "howarth.at.gcc at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-65861-4@http.gcc.gnu.org/bugzilla/> (raw)

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 <string>
#include <iterator>
#include <algorithm>
void f(std::istream &s, std::string x) {
      std::istreambuf_iterator<char> eod;
      std::search(std::istreambuf_iterator<char>(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<char, std::__1::char_traits<char> >'
        : __sbuf_(__s.rdbuf()) {}
                     ^
test3.cpp:6:19: note: in instantiation of member function
'std::__1::istreambuf_iterator<char,
      std::__1::char_traits<char> >::istreambuf_iterator' requested here
      std::search(std::istreambuf_iterator<char>(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<typename
add_lvalue_reference<_BinaryPredicate>::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::istreambuf_iterator<char,
      std::__1::char_traits<char> >, std::__1::__wrap_iter<char *>,
std::__1::__equal_to<char, char> >' 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::istreambuf_iterator<char,
std::__1::char_traits<char> >, std::__1::__wrap_iter<char *>
      >' requested here
      std::search(std::istreambuf_iterator<char>(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<char,
char> &, _RandomAccessIterator1 =
      std::__1::istreambuf_iterator<char, std::__1::char_traits<char> >,
_RandomAccessIterator2 =
      std::__1::__wrap_iter<char *>] not viable: no known conversion from
'typename
      std::iterator_traits<istreambuf_iterator<char, char_traits<char> >
>::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<char,
char> &, _ForwardIterator1 =
      std::__1::istreambuf_iterator<char, std::__1::char_traits<char> >,
_ForwardIterator2 = std::__1::__wrap_iter<char
      *>] not viable: no known conversion from 'typename
std::iterator_traits<istreambuf_iterator<char, char_traits<char>
      > >::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.


             reply	other threads:[~2015-04-23 14:43 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-23 14:43 howarth.at.gcc at gmail dot com [this message]
2015-04-23 15:01 ` [Bug libstdc++/65861] " glisse at gcc dot gnu.org
2015-04-23 15:04 ` redi at gcc dot gnu.org
2015-04-23 15:14 ` howarth.at.gcc at gmail dot com
2015-04-23 15:16 ` howarth.at.gcc at gmail dot com
2015-04-23 15:21 ` redi at gcc dot gnu.org
2015-04-23 15:27 ` redi at gcc dot gnu.org
2015-04-25 10:48 ` howarth.at.gcc at gmail dot com
2015-04-25 13:40 ` redi at gcc dot gnu.org
2015-05-02 10:12 ` redi at gcc dot gnu.org
2021-12-06  5:19 ` [Bug c++/65861] " pinskia at gcc dot gnu.org
2021-12-06 10:42 ` redi at gcc dot gnu.org
2021-12-06 14:06 ` redi at gcc dot gnu.org
2021-12-06 22:01 ` pinskia at gcc dot gnu.org
2022-01-09  0:37 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-65861-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).