<div dir="ltr">On Wed, Oct 23, 2013 at 6:06 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>Hi Richard / Karen,<br>
<br></div>Thanks for making things clearer. <br></div>Now how do we go about handling this sort of behavior? <br><br></div>Do we throw an error message just like g++ does? Wont it be better to print an error message instead of an infinite loop?<br>
</div></div></blockquote><div><br></div><div>We don't know the loop is infinite, but we should probably give up after some number of iterations.</div><div> </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>Also if you could please elaborate a bit on how we can "limit the number of times we go around the loop looking for an overloaded operator-> in Sema::<div>ActOnStartCXXMemberReference" ? <br>
</div></div></blockquote><div><br></div><div>Add a counter to the "while (BaseType->isRecordType())" loop. Bail out with a diagnostic if it hits the limit.</div><div> </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>Thanks,<br></div><div>Rahul<br></div><div><br><br></div></div><div class=""><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Oct 23, 2013 at 3:30 AM, Karen Shaeffer <span dir="ltr"><<a href="mailto:shaeffer@neuralscape.com" target="_blank">shaeffer@neuralscape.com</a>></span> wrote:<br>

<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><div>On Tue, Oct 22, 2013 at 02:54:08PM -0700, Richard Smith wrote:<br>

> On Tue, Oct 22, 2013 at 2:03 PM, Karen Shaeffer <<a href="mailto:shaeffer@neuralscape.com" target="_blank">shaeffer@neuralscape.com</a>>wrote:<br>
><br>
> > On Tue, Oct 22, 2013 at 12:14:25PM -0700, Richard Smith wrote:<br>
> > > On Tue, Oct 22, 2013 at 2:45 AM, Rahul Jain <<a href="mailto:1989.rahuljain@gmail.com" target="_blank">1989.rahuljain@gmail.com</a><br>
> > >wrote:<br>
> > ><br>
> > > ><br>
> > > > Hi all,<br>
> > > ><br>
> > > > clang version 3.4 (192772)<br>
> > > ><br>
> > > > 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>
> > > > This TC goes into an infinite loop when compiled. Ideally it should<br>
> > throw<br>
> > > > the error<br>
> > > > recursive template instantiation exceeded maximum depth of 256.<br>
> > > ><br>
> > ><br>
> > > That's not the right behavior; there's no recursive template<br>
> > instantiation<br>
> > > here. Each operator-> is instantiated from within the context of 'main',<br>
> > > not from within some other instantiation.<br>
> > ><br>
> > > If we want to limit this, we should put a limit on the number of times we<br>
> > > go around the loop looking for an overloaded operator-><br>
> > > in Sema::ActOnStartCXXMemberReference. However, I've seen people use this<br>
> > > in practice in template metaprogramming to get around the recursive<br>
> > > template instantiation depth, so this might break existing code.<br>
> ><br>
> > Hi Richard,<br>
> ><br>
> > Just checked, and g++-4.7.2 doesn't give a 'recusive template<br>
> > instantiation' error.<br>
> > The error is:<br>
> ><br>
> > error: template instantiation depth exceeds maximum of 900 (use<br>
> > -ftemplate-depth= to increase the maximum) instantiating ‘a<(n + 1)><br>
> > a<n>::operator->() [with int n = 900]’<br>
> ><br>
><br>
> This is their recursive template instantiation error. I'm not sure why they<br>
> chose to diagnose this problem in that way; there is no recursive<br>
> instantiation here. The loop is in [over.ref](13.5.6)p1:<br>
><br>
> "An expression x->m is interpreted as (x.operator->())->m for a class<br>
> object x of type T if T::operator->() exists and if the operator is<br>
> selected as the best match function by the overload resolution mechanism."<br>
><br>
> This rule gets applied repeatedly, outside of any template instantiation.<br>
><br>
><br>
> > In the standard at [temp.inst]<br>
> ><br>
><br>
> > <14.7.1 note d><br>
> > There is an implementation-defined quantity that specifies the limit on<br>
> > the total depth<br>
> > of recursive instantiations, which could involve more than one template.<br>
> > The result of an<br>
> > infinite recursion in instantiation is undefined.<br>
> ><br>
><br>
> This is not what's happening in this case.<br>
<br>
</div></div>Hi Richard,<br>
I understand it is not what is happening. I just included the <14.7.2 note 15><br>
for clarity. I think the g++ error message is crystal clear. And the practicality<br>
of it is obvious.<br>
<br>
Thanks for your comments.<br>
<div><div><br>
enjoy,<br>
Karen<br>
--<br>
Karen Shaeffer                 Be aware: If you see an obstacle in your path,<br>
Neuralscape Services           that obstacle is your path.        Zen proverb<br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>