<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Sep 5, 2013 at 10:41 AM, Andrej Mitrovic <span dir="ltr"><<a href="mailto:andrej.mitrovich@gmail.com" target="_blank">andrej.mitrovich@gmail.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 class="im">On 9/5/13, Timothee Cour <<a href="mailto:thelastmammoth@gmail.com">thelastmammoth@gmail.com</a>> wrote:<br>

> So would it be possible to detect such kind of errors (ie CT error<br>
> regardless of template params) without having to instantiate the template?<br>
<br>
</div>How would you semantically analyze the following without instantiating it?:<br>
<br>
-----<br>
template T(X)<br>
{<br>
    enum T = X.foo;<br>
}<br>
-----<br>
<br>
Note how the above can be both valid and invalid based on the template<br>
parameters:<br>
<br>
-----<br>
class C<br>
{<br>
    enum int foo = 1;<br>
}<br>
<br>
class D<br>
{<br>
    int foo = 1;<br>
}<br>
<br>
void main()<br>
{<br>
    enum foo = T!C;  // ok<br>
    enum foo = T!D;  // fail<br>
}<br>
-----<br></blockquote><div><br></div><div>I specifically said I was only considering <span style="font-family:arial,sans-serif;font-size:12.727272033691406px">semantically always incorrect code (ie regardless of template parameters), so that example doesn't fly.</span></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">
<br>
There's so much context-dependent semantics in a template that eager<br>
semantic analysis of templates which haven't been instantiated would<br>
be limited to work for only very simple templates. So I don't think it<br>
would be worth even trying to analyze without instantiating.<br>
<br>
Also, I think it would likely be extremely hard to implement in the<br>
compiler, and could possible lead to false-positives (compiles) or<br>
false-negatives (doesn't compile) cases.<br>
<br>
And finally, compile times would literally explode with eager semantic analysis.<br></blockquote><div><br></div><div>As HS Teoh explained, this could actually be done at very little cost for symbol scope resolution. It is done once per template.</div>
</div><br></div></div>