Suspected compiler bug (was: Using different instances of the 'std::basic_string<>' template)

  • Thread starter Hendrik Schober
  • Start date
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>::blush: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
 
D

David Lowndes

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

It looks like you might be right.

FWIW, I can repro the problem with VS7.1, but it builds fine with the
Whidbey alpha compiler.

Dave
 
H

Hendrik Schober

David Lowndes said:
It looks like you might be right.

FWIW, I can repro the problem with VS7.1, but it builds fine with the
Whidbey alpha compiler.

I don't think I can expect a soon fix for that?
<sigh>
This breaks a lot of my code which compiles using
CodeWarrior and GCC. I'm not sure how (if) I can
work around this.

Schobi

--
(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
 
D

David Lowndes

I don't think I can expect a soon fix for that?

I really don't know.

If you report the problem to MS product support, and there isn't a
work-around, they may have a bug fix available (that's not fully
tested).

Dave
 
H

Hendrik Schober

David Lowndes said:
I really don't know.

If you report the problem to MS product support, and there isn't a
work-around, they may have a bug fix available (that's not fully
tested).

Mhmm. How would I have to start to do this?

Schobi

--
(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
 
D

David Lowndes

If you report the problem to MS product support, and there isn't a
Mhmm. How would I have to start to do this?

I don't know of any other way other than to phone your regional MS
Product Support phone number.

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top