home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 31,967 of 33,346   
   Alf P. Steinbach to Roman W   
   Re: Is this legal C++ code?   
   02 Mar 12 02:38:35   
   
   2817dc6f   
   From: alf.p.steinbach+usenet@gmail.com   
      
   On 29.02.2012 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?   
      
   C++11 (from N3290) §14.7.1/15: "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"   
      
      
   Cheers & hth.,   
      
   - Alf   
      
      
   --   
         [ 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)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca