a1fe4e22   
   From: daniel.kruegler@googlemail.com   
      
   Am 02.10.2011 09:26, schrieb puppi:   
   > Consider the following program:   
   >   
   >   
   > template   
   > class loop1 {   
   > public:   
   > typedef typename loop1 >::RET RET;   
   > };   
   >   
   > template   
   > class loop2 {   
   > public:   
   > typedef typename loop2 >::RET RET;   
   > };   
   >   
   > // typedef loop1::RET RET1;   
   > typedef loop2::RET RET2;   
   >   
   >   
   > That's the whole program, since there's no use for a main in a program   
   > which has the purpose to trigger a compile-time error.   
   > If the RET1 typedef is uncommented, the expected happens: compilation   
   > enters a loop until the maximum template depth is reached, outputting   
   > an error and aborting.   
      
   Yes, that is conforming. Let me add here that the behaviour of either of your   
   examples is undefined.   
      
   > However, I can't truly understand why the same doesn't happen with the   
   > RET2 typedef. Instead, compilation appears to enter a true infinite   
   > loop, without outputting any error and consuming more and more RAM to   
   > account for the instantiations.   
   >   
   > Analyzing what should happen, I would assume the following:   
   > 1) An attempt to instantiate loop2 is made.   
   > 2) To instantiate loop2, loop2 > must be   
   > instantiated.   
   > 3) To instantiate loop2 >, loop2,   
   > loop2 > > must be instantiated.   
   > And so forth. That seems like a recursive pattern which should   
   > overflow the maximum template depth. Why it doesn't truly boggles me.   
   > Does anyone have any insight on that?   
      
   Note that this variant is a kind of two-dimensional "explosion", while your   
   first example is only a one-dimensional "explosion". In the "2D" case every   
   instantiation level increases the type list by expansion *and* the   
   instantiation depth, which is even    
   more costly than a simple infinite instantiation. For every instantiation   
   attempt the complexity increases linear. I can only assume that the compiler   
   meets the memory limit before the instantiation limit.   
      
   HTH & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|