I haven't found any other place you can report a bug with Visual Studio, so I figured I'd try here, although I don't think any MS people read these.
I'm deriving a class from the templated std::streambuf. In MSVC.NET 2002 and also in GCC 3 and te Comeau compiler, this code compiles. However in MSVC.NET 2003 alone does it not compile.
I had to implement a small workaround only for MSVC.NET 2003. The code for the class is as follows: class goutbuf : public std::streambuf { public: goutbuf(); ~goutbuf();
/** * If set, the next output will be an mlprintf instead of a mprintf, with * the specified coordinates. */ void setNextWriteLoc(int x, int y);
protected: int sync(); void flush_output();
#if (_MSC_VER == 1310 ) //While still technically correct and valid, it's not quite as robust as the //next line because this makes the assumption on what traits_type is defined //as. int_type overflow(int_type meta = std::char_traits<char>::eof()); #else //For some reason, in MSVC.NET 2003 alone (not 2002), this line generates //the following error: //error C2653: 'char_traits<char>' : is not a class or namespace name int_type overflow(int_type meta = traits_type::eof()); #endif
Jason Winnebeck wrote: > I haven't found any other place you can report a bug with Visual > Studio, > so I figured I'd try here, although I don't think any MS people read > these.
They do.
> I'm deriving a class from the templated std::streambuf. In MSVC.NET > 2002 and also in GCC 3 and te Comeau compiler, this code compiles. > However in MSVC.NET 2003 alone does it not compile.
It would help if you could post a complete example that illustrates the behavior you're reporting as a bug. I assume you did #include <string>? I'm not sure that std::char_traits is required to be defined if you haven't explicitly included <string>
> It would help if you could post a complete example that illustrates the > behavior you're reporting as a bug. I assume you did #include <string>? > I'm not sure that std::char_traits is required to be defined if you haven't > explicitly included <string>
I would expect that to be the first question someone would ask me, and I have two very good answers for this.
The first answer is, if you look at the previous code with the workaround, switching to std::char_traits<char> does work.
The second answer is that I am not using char_traits at all in the "correct" code (the second part of the #if). I'm using std::streambuf::traits_type. And <streambuf> is included, espically seeing as goutbuf is declared from streambuf.
If we look in the standard, std::streambuf::traits_type is a member (a typedef) of the std::streambuf class, and its definition is std::char_traits<char> for std::streambuf (which is std::basic_streambuf<char, std::char_traits<char> >) as defined by 27.5 of the standard. 27.5.2 defines the traits_type typedef for std::streambuf.
The code using traits_type compiles on MSVC.NET 2002, GCC 3, and Comeau. I can't see a reason why it should not work by the standard (and thus for 2003).
Perhaps, though, I will try including it. But as I said, replacing the typedef'd element of streambuf with its definition fixes the problem, which is, I believe, to be a very clear sign that something is wrong.
If typedef A B; And if: B x; gives an error that "A" is not defined, but A x; does work, I would say this is not right.
Jason Winnebeck wrote: > Carl Daniel [VC++ MVP] wrote: >> It would help if you could post a complete example that illustrates >> the behavior you're reporting as a bug. I assume you did #include >> <string>? I'm not sure that std::char_traits is required to be >> defined if you haven't explicitly included <string> > Perhaps, though, I will try including it. But as I said, replacing > the typedef'd element of streambuf with its definition fixes the > problem, which is, I believe, to be a very clear sign that something > is wrong.
It may well be. Without a complete example it's much harder to speculate. With a complete example it's much more likely that a bug, if there is one, will get fixed. FWIW it does sound like a bug to me.
<cpdaniel_remove_this_and_nos...@mvps.org.nospam> wrote: >Jason Winnebeck wrote: >> Carl Daniel [VC++ MVP] wrote: >>> It would help if you could post a complete example that illustrates >>> the behavior you're reporting as a bug. I assume you did #include >>> <string>? I'm not sure that std::char_traits is required to be >>> defined if you haven't explicitly included <string>
>> Perhaps, though, I will try including it. But as I said, replacing >> the typedef'd element of streambuf with its definition fixes the >> problem, which is, I believe, to be a very clear sign that something >> is wrong.
>It may well be. Without a complete example it's much harder to speculate. >With a complete example it's much more likely that a bug, if there is one, >will get fixed. FWIW it does sound like a bug to me.
This does it:
#include <streambuf>
class goutbuf : public std::streambuf { protected: int_type overflow(int_type meta = traits_type::eof());
> class goutbuf : public std::streambuf { > protected: > int_type overflow(int_type meta = traits_type::eof()); > };
Tom -
Thanks for finding a tiny repro!
Jason -
This appears to be fixed in the Whidbey alpha. If this is causing you significant problems in yoiur production work, you should contact Product Support Services.
>>class goutbuf : public std::streambuf { >>protected: >> int_type overflow(int_type meta = traits_type::eof()); >>};
> Tom -
> Thanks for finding a tiny repro!
> Jason -
> This appears to be fixed in the Whidbey alpha. If this is causing you > significant problems in yoiur production work, you should contact Product > Support Services.
> -cd
Wow thanks for the replies. It's nice to know that there is somewhere to report these things. I wonder if I should try to find a repro case for a bug I found in the optimizer. I found an issue where I wrote a random number generator and the function was inlined very incorrectly. The problem was solved by turning off inlining for that function alone. (or was also solved by turning off whole program optimizations as the RNG function was in another file). I believe IIRC the statements were reordered improperly such that the integer code ran only once for all the calls and the floating point code was run multiple times, so that if I called my RNG 4 times and it returned let's say 20, and I called "getrnd()/2" four times in a row, I'd get 20, 10, 5, 2.5.
But I digress, so if I want to do that I will probably file it on a different VC newsgroup after narrowing the code down.
As for the char_traits bug, it is bothersome, but I have to deal with it anyway as the code is in a library distributed as source code, and when using that preprocessor test it works fine.
Jason Winnebeck wrote: > Wow thanks for the replies. It's nice to know that there is somewhere > to report these things. > I wonder if I should try to find a repro case > for a bug I found in the optimizer. I found an issue where I wrote a > random number generator and the function was inlined very incorrectly.
If you can produce a repro, please post it. The VC team is usually very interested in fixing codegen bugs, but having a repro is for all practical purposes a necessity.
> The problem was solved by turning off inlining for that function > alone. (or was also solved by turning off whole program > optimizations as the > RNG function was in another file). I believe IIRC the statements were > reordered improperly such that the integer code ran only once for all > the calls and the floating point code was run multiple times, so that > if > I called my RNG 4 times and it returned let's say 20, and I called > "getrnd()/2" four times in a row, I'd get 20, 10, 5, 2.5.
It might be that your code exhibited undefined behavior too - a repro will tell.
> But I digress, so if I want to do that I will probably file it on a > different VC newsgroup after narrowing the code down.
I'd suggest posting it to microsoft.public.vc.language.
> As for the char_traits bug, it is bothersome, but I have to deal with > it anyway as the code is in a library distributed as source code, and > when using that preprocessor test it works fine.
On Mon, 16 Feb 2004 15:29:21 -0500, Jason Winnebeck
<gill...@mail.rit.nspam.edu> wrote: >As for the char_traits bug, it is bothersome, but I have to deal with it >anyway as the code is in a library distributed as source code, and when >using that preprocessor test it works fine.
This simple workaround seems to fix the problem:
#include <streambuf>
class goutbuf : public std::streambuf { protected: int_type overflow(int_type meta = std::streambuf::traits_type::eof());
tom_usenet wrote: > This simple workaround seems to fix the problem: > int_type overflow(int_type meta = > std::streambuf::traits_type::eof()); > };
Oh I will try that one out tonight. That would allow for me to get rid of the #if preprocessor statement, and while although overly redundant, it is still as correct as using traits_type, I believe. My workaround invovled using char_traits<char> directly which should always be correct since it is specified in the standard, but I still feel better using the more generic approach.
It's a bug in MSVC.NET. Compile the following code. It produces the same error.
#include <limits> #undef max
template < typename T > class A { protected: typedef std::numeric_limits< T > MinMaxTy; private: T t_; public: A(const T t= MinMaxTy::max()) : t_(t) {}
};
template < typename T > class AA : public A< T > { typedef A< T > inherited; typedef typename inherited::MinMaxTy MinMaxTy; public: AA(const T t= MinMaxTy::max()) : inherited(t) {}
> I haven't found any other place you can report a bug with Visual Studio, > so I figured I'd try here, although I don't think any MS people read these.
> I'm deriving a class from the templated std::streambuf. In MSVC.NET > 2002 and also in GCC 3 and te Comeau compiler, this code compiles. > However in MSVC.NET 2003 alone does it not compile.
> I had to implement a small workaround only for MSVC.NET 2003. The code > for the class is as follows: > class goutbuf : public std::streambuf { > public: > goutbuf(); > ~goutbuf();
> /** > * If set, the next output will be an mlprintf instead of a mprintf, with > * the specified coordinates. > */ > void setNextWriteLoc(int x, int y);
> protected: > int sync(); > void flush_output();
> #if (_MSC_VER == 1310 ) > //While still technically correct and valid, it's not quite as robust > as the > //next line because this makes the assumption on what traits_type is > defined > //as. > int_type overflow(int_type meta = std::char_traits<char>::eof()); > #else > //For some reason, in MSVC.NET 2003 alone (not 2002), this line generates > //the following error: > //error C2653: 'char_traits<char>' : is not a class or namespace name > int_type overflow(int_type meta = traits_type::eof()); > #endif