Re: [Mingw-users] [BUG] - member is template<T>: ice in 4.2.1-sjlj (mingw32-2), bad compilation in 3.4.5
- Date: Thu, 20 Dec 2007 14:32:48 +0000
- From: Greg Chicares <gchicares@xxxxxxxxxxxxx>
- Subject: Re: [Mingw-users] [BUG] - member is template<T>: ice in 4.2.1-sjlj (mingw32-2), bad compilation in 3.4.5
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.
> test.cpp: In destructor 'AutoCounter<T>::~AutoCounter() [with T = Outer]':
> test.cpp:53: instantiated from 'AutoCounter<Outer>::CleanupCheck AutoCounter<O
> uter>::verifier'
> test.cpp:53: instantiated from 'AutoCounter<T>::~AutoCounter() [with T = Outer
> ]'
> test.cpp:76: instantiated from here
> test.cpp:53: internal compiler error: in instantiate_decl, at cp/pt.c:12094
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. And add "#include <ostream>" 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 <iostream>, 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. Actually,
the code is incorrect; if you want a second compiler's opinion
to confirm that, then use
http://www.comeaucomputing.com/tryitout/
> template<> int AutoCounter<Outer>::count = 0;
Following the example in C++2003 14.7/6, I'd write:
template<typename T> int AutoCounter<T>::count = 0;
> template<typename> AutoCounter<Outer>::CleanupCheck AutoCounter<Outer>::verifier;
First try this:
template<typename T> AutoCounter<T>::CleanupCheck AutoCounter<T>::verifier;
and you'll get a normal error message instead of an ICE.
Then add the missing ingredient, one more 'typename':
template<typename T> typename AutoCounter<T>::CleanupCheck AutoCounter<T>::verifier;
and it works.
/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.]
/tmp[0]$./a
created[0]
created[1]
destroying[0]
~CleanupCheck()
All 5Outer objects not cleaned up
-------------------------------------------------------------------------
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