<div dir="ltr"><div dir="ltr"><div dir="ltr">On Mon, Apr 29, 2019 at 10:13 AM Nicolas Lesser via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Lorenzo Cavallini via cfe-dev wrote:<br>
> Hello everyone,<br>
> I'm writing to report what I think is an issue related to Class Template<br>
> Argument Deduction (CTAD for short). Compiling this short snippet:<br>
> <br>
> #include <cstdio><br>
> #include <vector><br>
> <br>
> template<typename T><br>
> void printV(const std::vector<T>& v)<br>
> {<br>
>     if (v.size() == 1) {<br>
>         printf("%d ", v[0]);<br>
>         return;<br>
>     }<br>
>     int middle = v.size()/2;<br>
>     printV(std::vector{v.begin(), v.end()+middle});<br>
> }<br>
> <br>
> int main()<br>
> {<br>
>     std::vector<int> v = {10,1};<br>
>     printV(v);<br>
>     return 0;<br>
> }<br>
> <br>
> will result in clang generating an infinite error report (at least, I left<br>
> it running for several hours, then I stopped the process...), due to (I<br>
> guess) wrongly deducted template arguments. If the "printf" line is<br>
> removed, no error is generated but clang will compile for what it looks<br>
> like forever (the process is constantly at 100% and does not stop after<br>
> several hours).<br>[...]<br>
<br>
Very interesting find! You are correct that this happens due to infinite template recursion, not due to a bug in the standard. [...]<br>
This also has infinite template recursion, but in that case, gcc and clang stop after a specified -ftemplate-depth. Seems like in your specific example this limit is somehow bypassed.<br></blockquote><div><br></div><div>The limit is not bypassed. But the default -ftemplate-depth is 1024, so the number of messages output is (1+2+3+4+...+1023+1024), and the size of each message is O(n), so in total we're seeing about O(1024*1024*1024) characters printed. (Except that on trunk, Clang already skips most of the messages output, which takes the size of the output back down to O(1024*1024) — that is, O(1024) messages each of size O(1024) characters.)</div><div><br></div><div>A local build of Clang trunk on my machine takes 148 seconds to finish printing all the messages in Lorenzo's original test.</div><div><br></div><div><p style="margin:0px;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">$ time $ROOT/llvm/build/bin/clang++ x.cc -std=c++17 2>&1 | wc</span></p>
<p style="margin:0px;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">   18211 8373912 128703709</span></p>
<p style="margin:0px;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;min-height:15px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">real<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>1m28.044s</span></p>
<p style="margin:0px;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">user<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>1m26.359s</span></p>
<p style="margin:0px;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">sys<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>0m2.073s</span></p></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures">–Arthur</span></div></div></div></div>