Bug 16154 - input iterator concept too restrictive
Summary: input iterator concept too restrictive
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 3.4.1
Assignee: Paolo Carlini
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-23 09:14 UTC by cludwig
Modified: 2004-06-24 08:48 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-06-23 10:30:00


Attachments
test program and compiler output (78.14 KB, application/x-tbz)
2004-06-23 09:16 UTC, cludwig
Details

Note You need to log in before you can comment on or make changes to this bug.
Description cludwig 2004-06-23 09:14:52 UTC
The input iterator concept checks performed if std::copy is called are too 
restrictive. Neither in section 24.1.1 nor in section 25.2 of the C++ standard 
I see any requirement that input iterators have to be default constructible. 
But the compilation of the following program fails anyway due to a failed 
DefaultConstructibleConcept check. 
 
cludwig@lap200:~/C++/gcc3.4/tmp> cat input-iterator.cc 
#include <iterator> 
#include <string> 
#include <iostream> 
#include <algorithm> 
 
class myInputIterator : public std::iterator<std::input_iterator_tag, char> { 
  std::string data; 
 
public: 
  // past-the-end iterators can be constructed 
  // by myInputIterator("") 
  explicit myInputIterator(std::string const& input) 
    : data(input) { 
  } 
 
  value_type operator*() { 
    return data.at(data.length() - 1); 
  } 
 
  myInputIterator& operator++() { 
    if(!data.empty()) { 
      data.resize(data.length() - 1); 
    } 
    return *this; 
  } 
 
  myInputIterator operator++(int) { 
    myInputIterator result(*this); 
    ++(*this); 
    return result; 
  } 
 
  friend bool operator==(myInputIterator const& lhs, 
                         myInputIterator const& rhs); 
}; 
 
 
bool operator==(myInputIterator const& lhs, myInputIterator const& rhs) { 
  return lhs.data == rhs.data; 
} 
 
 
bool operator!=(myInputIterator const& lhs, myInputIterator const& rhs) { 
  return !(lhs == rhs); 
} 
 
 
int main() { 
  std::copy(myInputIterator("Hello world!"), myInputIterator(""), 
            std::ostream_iterator<char>(std::cout)); 
  return 0; 
} 
 
 
I am going to attach the compiler output. 
 
Regards 
 
Christoph
Comment 1 cludwig 2004-06-23 09:16:42 UTC
Created attachment 6610 [details]
test program and compiler output
Comment 2 CVS Commits 2004-06-23 16:04:00 UTC
Subject: Bug 16154

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	paolo@gcc.gnu.org	2004-06-23 16:03:52

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/bits: boost_concept_check.h 

Log message:
	2004-06-23  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/16154
	* include/bits/boost_concept_check.h (struct _TrivialIteratorConcept):
	Don't require the _DefaultConstructibleConcept.
	(struct _ForwardIteratorConcept): Require it here.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&r1=1.2531&r2=1.2532
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/boost_concept_check.h.diff?cvsroot=gcc&r1=1.17&r2=1.18

Comment 3 CVS Commits 2004-06-23 16:09:51 UTC
Subject: Bug 16154

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	paolo@gcc.gnu.org	2004-06-23 16:09:48

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/bits: boost_concept_check.h 

Log message:
	2004-06-23  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/16154
	* include/bits/boost_concept_check.h (struct _TrivialIteratorConcept):
	Don't require the _DefaultConstructibleConcept.
	(struct _ForwardIteratorConcept): Require it here.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.2224.2.130&r2=1.2224.2.131
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/boost_concept_check.h.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.13.12.4&r2=1.13.12.5

Comment 4 Paolo Carlini 2004-06-23 16:11:15 UTC
Fixed for 3.4.1.
Comment 5 Benjamin Kosnik 2004-06-24 02:57:15 UTC
It would probably be a good idea to update to current boost concept checking.

-benjamin
Comment 6 Paolo Carlini 2004-06-24 08:48:57 UTC
> It would probably be a good idea to update to current boost concept checking.

Definitely. Unfortunately, however, the task is not trivial: many things have
changed in the general structure. I'll try...
Comment 7 CVS Commits 2004-07-12 21:56:08 UTC
Subject: Bug 16154

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	hammer-3_3-branch
Changes by:	paolo@gcc.gnu.org	2004-07-12 21:55:55

Modified files:
	libstdc++-v3   : ChangeLog.hammer 
	libstdc++-v3/include/bits: boost_concept_check.h 

Log message:
	2004-07-12  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/16154
	* include/bits/boost_concept_check.h (struct _TrivialIteratorConcept):
	Don't require the _DefaultConstructibleConcept.
	(struct _ForwardIteratorConcept): Require it here.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.hammer.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=1.1.2.18&r2=1.1.2.19
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/boost_concept_check.h.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=1.9.12.1&r2=1.9.12.2