libstdc++/9826: operator>>(basic_istream, basic_string) fails to compile with custom traits
Mon Feb 24 09:26:00 GMT 2003

>Number:         9826
>Category:       libstdc++
>Synopsis:       operator>>(basic_istream, basic_string) fails to compile with custom traits
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 24 09:26:00 UTC 2003
>Release:        gcc-3.2.1
Red Hat Linux 8.0
If traits_type::int_type is not convertible to char_type, operator>>(basic_istream, basic_string) fails to compile.

This is because the implementation of this function passes an object of type int_type to ctype::is, this is a serious error also when int_type is int and char_type is char if char is signed.
See attachment.

Content-Type: text/plain; name=""
Content-Disposition: inline; filename=""

#include <istream>
#include <streambuf>
#include <string>

struct MyChar
	int val;

struct MyInt
	long val;

class MyState

class MyTraits
	typedef MyChar char_type;
	typedef MyInt int_type;
	typedef std::streampos pos_type;
	typedef std::streamoff off_type;
	typedef MyState state_type;

	static void
	assign(char_type& __c1, const char_type& __c2);

	static bool
	eq(const char_type& __c1, const char_type& __c2);

	static bool
	lt(const char_type& __c1, const char_type& __c2);

	static int
	compare(const char_type* __s1, const char_type* __s2, size_t __n);

	static size_t
	length(const char_type* __s);

	static const char_type*
	find(const char_type* __s, size_t __n, const char_type& __a);

	static char_type*
	move(char_type* __s1, const char_type* __s2, size_t __n);

	static char_type*
	copy(char_type* __s1, const char_type* __s2, size_t __n);

	static char_type*
	assign(char_type* __s, size_t __n, char_type __a);

	static char_type
	to_char_type(const int_type& __c);

	static int_type
	to_int_type(const char_type& __c);

	static bool
	eq_int_type(const int_type& __c1, const int_type& __c2);

	static int_type

	static int_type
	not_eof(const int_type& __c);

class Buf : public std::basic_streambuf<MyChar, MyTraits>

int main()
	using namespace std;

	Buf buf;
	basic_string<MyChar, MyTraits> str;
	basic_istream<MyChar, MyTraits> stream(&buf);
	stream >> str;

	return 0;

More information about the Gcc-bugs mailing list