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,965 of 33,346   
   =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to Roman W   
   Re: Is this legal C++ code?   
   02 Mar 12 02:35:35   
   
   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)   

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


(c) 1994,  bbs@darkrealms.ca