2817dc6f   
   From: daniel.kruegler@googlemail.com   
      
   On 2012-02-29 12:57, Roman W wrote:   
   > ===============================   
   > #include   
   >   
   > template struct wrapped   
   > {   
   > wrapped(const T&) {}   
   > };   
   >   
   > template wrapped wrappit(const T& x)   
   > {   
   > return wrapped(x);   
   > }   
   >   
   > template int run_function(const T& x, bool wrapped)   
   > {   
   > if (wrapped) {   
   > return 0;   
   > } else {   
   > return run_function(wrappit(x), true) + 1;   
   > }   
   > }   
   >   
   > int main()   
   > {   
   > std::cout<< run_function(0.5, false)<< std::endl;   
   > }   
   > ===============================   
   >   
   > It can never compile, but is it actually illegal according to the C++   
   > standard?   
      
   It depends what you mean with illegal. The standard has added words that   
   declare your program as having undefined behaviour, see [temp.inst] p15:   
      
   "There is an implementation-defined quantity that specifies the limit on   
   the total depth of recursive instantiations, which could involve more   
   than one template. The result of an infinite recursion in instantiation   
   is undefined."   
      
   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)   
|