<div dir="ltr">On Tue, Oct 22, 2013 at 2:45 AM, Rahul Jain <span dir="ltr"><<a href="mailto:1989.rahuljain@gmail.com" target="_blank">1989.rahuljain@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><br></div>Hi all,<br>
<br>clang version 3.4 (192772)<br><br></div>This is with respect to the following gcc testsuite TC:<br>
<br>template< int n ><br>struct a {<br> a< n+1 > operator->()<br>
{<br> return a< n+1 >();<br> }<br>};<br><br>int main() {<br> a<0>()->x; <br>}<br><br><br></div>This TC goes into an infinite loop when compiled. Ideally it should throw the error<br>
recursive template instantiation exceeded maximum depth of 256.<br></div></div></div></blockquote><div><br></div><div>That's not the right behavior; there's no recursive template instantiation here. Each operator-> is instantiated from within the context of 'main', not from within some other instantiation.</div>
<div><br></div><div>If we want to limit this, we should put a limit on the number of times we go around the loop looking for an overloaded operator-> in Sema::ActOnStartCXXMemberReference. However, I've seen people use this in practice in template metaprogramming to get around the recursive template instantiation depth, so this might break existing code.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div><div></div>On initial investigation I found that when the constructor <br>Sema::InstantiatingTemplate::<br>InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,<br>
Decl *Entity,<br> SourceRange InstantiationRange);<br><br></div><div>is run on each recursive object creation, <br>the first thing the constructor does is check whether the recursive instantiation depth is reached or not by calling the function <br>
<br>Invalid = CheckInstantiationDepth(PointOfInstantiation,<br> InstantiationRange);<br></div><div><br></div><div>The above function checks whether the size of SemaRef.ActiveTemplateInstantiations(a container which stacks all the template instantiations originating from a particular PointOfInstantiation) is within the limit as specified by templateinstantiationdepth(256 by default).<br>
<br></div><div>So far, so good.<br><br></div><div>Now when CheckInstantiationDepth returns false, the constructor pushes the current Inst using the following statement:<br>SemaRef.ActiveTemplateInstantiations.push_back(Inst);<br>
<br></div><div>Also the push_back function correctly increments the EndX value. <br><br><br></div><div>So ideally the size of SemaRef.ActiveTemplateInstantiations should increase from 1 to 2 to 3 to .....256 and than the error should get printed.<br>
<br></div><div>But, the EndX value which was incremented in the push_back function call is no longer reflected <br></div><div>in the size computation done as part of the function call CheckInstantiationDepth(PointOfInstantiation,<br>
InstantiationRange);.<br><br></div><div>i.e SemaRef.ActiveTemplateInstantiations.size() always returns zero in the function CheckInstantiationDepth.<br><br></div><div>My question is where is the EndX value getting reset after it was rightly incremented in the push_back function call?<br>
<br></div><div><br></div><div>Am I missing something in my analysis above? Any help on the same would be appreciated.<br><br></div><div>Thanks,<br></div><div>Rahul<br></div><div><br></div><div><br></div><div><br></div><div>
<div><br></div></div></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>