<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><br></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>