H
Hendrik Schober
Hi,
I had originally suspected this to be a bug
in the std lib, that's why I started a thred
in the STL newsgroup. However, it seems as if
it is a compiler bug, so I'm transfering it to
here.
The original code was this:
----- Original Message -----
From: "Hendrik Schober" <[email protected]>
Newsgroups: microsoft.public.vc.stl
Sent: Wednesday, October 29, 2003 10:04 PM
Subject: Using different instances of the 'std::basic_string<>' template
[...]
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
template< typename T >
struct CTraits {
template< typename T >
struct char_traits : public std::char_traits<char> {};
typedef
std::basic_string< char, char_traits<T>, std::allocator<char> >
string;
typedef
std::basic_ofstream< char, char_traits<T> >
ofstream;
};
struct tag {};
int main()
{
std::string sstr = "Hello, world!";
CTraits<tag>::string us( sstr.begin(), sstr.end() );
CTraits<tag>:fstream ofs("c:\\test.txt");
if( !ofs ) {std::cerr << "Cannot open file!\n";std::abort();}
ofs << us;
if( !ofs ) {std::cerr << "Cannot write to file!\n";std::abort();}
return 0;
}
[...]
This is a piece from the discussion about this:
Especially the last sentence strongly hints
at a compiler bug.
Schobi
[crossposted and f'up set to microsoft.public.dotnet.languages.vc]
--
(e-mail address removed) is never read
I'm Schobi at suespammers org
"And why should I know better by now/When I'm old enough not to?"
Beth Orton
I had originally suspected this to be a bug
in the std lib, that's why I started a thred
in the STL newsgroup. However, it seems as if
it is a compiler bug, so I'm transfering it to
here.
The original code was this:
----- Original Message -----
From: "Hendrik Schober" <[email protected]>
Newsgroups: microsoft.public.vc.stl
Sent: Wednesday, October 29, 2003 10:04 PM
Subject: Using different instances of the 'std::basic_string<>' template
[...]
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
template< typename T >
struct CTraits {
template< typename T >
struct char_traits : public std::char_traits<char> {};
typedef
std::basic_string< char, char_traits<T>, std::allocator<char> >
string;
typedef
std::basic_ofstream< char, char_traits<T> >
ofstream;
};
struct tag {};
int main()
{
std::string sstr = "Hello, world!";
CTraits<tag>::string us( sstr.begin(), sstr.end() );
CTraits<tag>:fstream ofs("c:\\test.txt");
if( !ofs ) {std::cerr << "Cannot open file!\n";std::abort();}
ofs << us;
if( !ofs ) {std::cerr << "Cannot write to file!\n";std::abort();}
return 0;
}
[...]
This is a piece from the discussion about this:
Bo Persson said:Hendrik Schober said:Bo Persson said:[...]
Could be a bug in the compiler.
I'd rather suspect the std lib. That's why
I posted here.
Yes, but I get the same error with both Dinkumware and my private
(gasp!) implementation of the standard library. It occurs at this line
inside basic_ofstream
virtual int_type overflow(int_type _MetaChar =
traits_type::eof())
{
where traits_type is a typedef for a template parameter, from a
typedef for a specialization of std::basic_filestream using a
templated class that inherits from std::char_traits. Or something
It can't resolve eof() because it thinks that traits_type (expanded to
char_traits<tag>) doesn't look like a class or namespace.
Also, if we move "our" char_traits outside CTraits, it compiles.
Bo Persson
Especially the last sentence strongly hints
at a compiler bug.
Schobi
[crossposted and f'up set to microsoft.public.dotnet.languages.vc]
--
(e-mail address removed) is never read
I'm Schobi at suespammers org
"And why should I know better by now/When I'm old enough not to?"
Beth Orton