Re: [Mingw-users] [BUG] - member is template<T>: ice in 4.2.1-sjlj (mingw32-2), bad compilation in 3
- Date: Thu, 20 Dec 2007 10:21:34 -0500
- From: John Brown <johnbrown105@xxxxxxxxxxx>
- Subject: Re: [Mingw-users] [BUG] - member is template<T>: ice in 4.2.1-sjlj (mingw32-2), bad compilation in 3
Greg Chicares wrote:
>
> On 2007-12-20 12:43Z, John Brown wrote:
>>
>> Compilation with gcc 3.4.5 is successful, but it crashes on the line:
>>
>> verifier.add(this); // first line in AutoCounter();
>> If I comment out this line, the program will run, but the output
>> will be wrong.
>>
>> If I compile with gcc-4.2.1-sjlj, I get an ICE:
>>
>> c:\mingw4\bin\g++ -g -frtti -o test test.cpp
>
> BTW, '-frtti' has been the default since before gcc-3.0 IIRC,
> so you don't have to specify it.
OK.
...
>
> First of all, it looks like you're striving to qualify all
> standard names explicitly (good), but there are some naked
> cout's and endl's.
What happened was, I made a small change to avoid having to post
require.h. Of course, without the std:: qualifier, the code that I posted
does not compile.
> And add "#include " because
> that's the only header that actually declares std::endl,
> even though it might work with some compilers that happen
> to include that header via , which the present
> standard does not require.
>
>> It compiles with Borland C++ 5.5 and gives the expected output:
>
> That's not strong evidence that the code is correct, because
> bc++5.5 is notoriously bad, especially for templates.
Didn't know that.
> Actually,
> the code is incorrect; if you want a second compiler's opinion
> to confirm that, then use
> http://www.comeaucomputing.com/tryitout/
I knew about that one, but I forgot.
>
> Following the example in C++2003 14.7/6, I'd write:
>
> template int AutoCounter::count = 0;
>
>> template AutoCounter::CleanupCheck AutoCounter::verifier;
>
> First try this:
>
> template AutoCounter::CleanupCheck AutoCounter::verifier;
>
> and you'll get a normal error message instead of an ICE.
> Then add the missing ingredient, one more 'typename':
>
> template typename AutoCounter::CleanupCheck AutoCounter::verifier;
>
> and it works.
OK. My code was wrong, but it's still a gcc bug, right?
1) gcc 3.4.5 compiled it when it should not have
2) gcc 4.1.2 gave an ICE instead of a normal error message
>
> /tmp[0]$/MinGW-20070825-sjlj/bin/g++-sjlj john-brown.cpp -W -Wall -std=c++98 -pedantic
> john-brown.cpp: In function 'int main()':
> john-brown.cpp:99: warning: unused variable 'p'
>
> [Eventually you'd clean up that warning.]
>
P was deliberately created to illustrate failure to destroy an object:
"All 5Outer objects not cleaned up"
Similarly, if you uncomment the second 'delete o;', it will tell you:
"Attempt to delete 5Outer twice"
Why does gcc have to use such ugly typenames? Another exercise produces
the following output:
g++
vector: St6vectorIiSaIiEE
vector: St6vectorIcSaIcEE
vector: St6vectorIfSaIfEE
vector: St6vectorISsSaISsEE
vector: St6vectorIbSaIbEE
bcc32
vector: std::vector<int,std::allocator>
vector: std::vector<char,std::allocator>
vector: std::vector<float,std::allocator>
vector: std::vector<std::basic_string<char,std::char_traits,std::a
llocator>,std::allocator<std::basic_string<char,std::char_traits,st
d::allocator>>>
vector: std::vector<std::allocator>
I understand that the standard does not impose a format on the name, but it
would have been better if it used the "real" name instead of the mangled
name. I don't know gcc's name-mangling algorithm, so even if I were inclined,
I cannot translate it myself.
_________________________________________________________________
The best games are on Xbox 360. Click here for a special offer on an Xbox 360 Console.
http://www.xbox.com/en-US/hardware/wheretobuy/
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users