?

Log in

 

Just a funny peace of code. How you compiler processes it? - Advanced C++ Community

About Just a funny peace of code. How you compiler processes it?

Previous Entry Just a funny peace of code. How you compiler processes it? Apr. 6th, 2007 @ 08:31 pm Next Entry
struct A {
};

template<typename TList>
struct MultipleInheritance :
  public TList::Head,
  public MultipleInheritance<typename TList::Tail>
{
};

template <typename T1>
struct RecTList {
  typedef T1 Head;
  typedef RecTList< RecTList<T1> > Tail;
};

typedef RecTList<A> ARecTList;

class RectClass : public MultipleInheritance<ARecTList> {};

int main() {
  return 0;
}
Leave a comment
[User Picture Icon]
From:omnifarious
Date:April 6th, 2007 05:47 pm (UTC)
(Link)

g++ did what I expected and told me that the template expansion recursion depth had been exceeded and that I needed to set a compiler option to increase the depth beyond 500. I suppose making the infinite recursion also involve inheritence is interesting and might throw some compilers in a weird tizzy though.

From:jetsnail
Date:April 6th, 2007 06:06 pm (UTC)
(Link)
Yeah, I run "gcc -c ./test_crec.cpp -ftemplate-depth-10000000". 1 hour left, it stills allocating memory and uses 100% of 4 CPUs :)

Microsoft Visual Studio 2005 Professional Edition with official Service Pack 1 just crashes:

1>------ Build started: Project: crec, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>x:\temp\crec\main.cpp(6) : fatal error C1001: An internal error has occurred in the compiler.
1>(compiler file 'msc1.cpp', line 1393)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
1>Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
1> x:\temp\crec\main.cpp(9) : see reference to class template instantiation 'MultipleInheritance' being compiled
1> x:\temp\crec\main.cpp(9) : see reference to class template instantiation 'MultipleInheritance
[Error: Irreparable invalid markup ('<rectlist<t1>') in entry. Owner must fix manually. Raw contents below.]

Yeah, I run "gcc -c ./test_crec.cpp -ftemplate-depth-10000000". 1 hour left, it stills allocating memory and uses 100% of 4 CPUs :)

Microsoft Visual Studio 2005 Professional Edition with official Service Pack 1 just crashes:

1>------ Build started: Project: crec, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>x:\temp\crec\main.cpp(6) : fatal error C1001: An internal error has occurred in the compiler.
1>(compiler file 'msc1.cpp', line 1393)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
1>Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
1> x:\temp\crec\main.cpp(9) : see reference to class template instantiation 'MultipleInheritance<TList>' being compiled
1> x:\temp\crec\main.cpp(9) : see reference to class template instantiation 'MultipleInheritance<RecTList<T1>>' being compiled
1>Build log was saved at "file://x:\Temp\crec\Debug\BuildLog.htm"
1>crec - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
[User Picture Icon]
From:omnifarious
Date:April 6th, 2007 06:42 pm (UTC)
(Link)

You might want to consider using Lightning Rose's txt2html converter, especially since C++ is very fond of the < character and somehwat fond of the & character.

[User Picture Icon]
From:ataxi
Date:April 8th, 2007 06:45 am (UTC)
(Link)
about as sensible as int func(int bob) { return func(++bob); } or something similar :-)
(Leave a comment)
Top of Page Powered by LiveJournal.com