On Thu, Sep 5, 2013 at 10:41 AM, Andrej Mitrovic <andrej.mitrov...@gmail.com
> wrote:

> On 9/5/13, Timothee Cour <thelastmamm...@gmail.com> wrote:
> > So would it be possible to detect such kind of errors (ie CT error
> > regardless of template params) without having to instantiate the
> template?
>
> How would you semantically analyze the following without instantiating it?:
>
> -----
> template T(X)
> {
>     enum T = X.foo;
> }
> -----
>
> Note how the above can be both valid and invalid based on the template
> parameters:
>
> -----
> class C
> {
>     enum int foo = 1;
> }
>
> class D
> {
>     int foo = 1;
> }
>
> void main()
> {
>     enum foo = T!C;  // ok
>     enum foo = T!D;  // fail
> }
> -----
>

I specifically said I was only considering semantically always incorrect
code (ie regardless of template parameters), so that example doesn't fly.


>
> There's so much context-dependent semantics in a template that eager
> semantic analysis of templates which haven't been instantiated would
> be limited to work for only very simple templates. So I don't think it
> would be worth even trying to analyze without instantiating.
>
> Also, I think it would likely be extremely hard to implement in the
> compiler, and could possible lead to false-positives (compiles) or
> false-negatives (doesn't compile) cases.
>
> And finally, compile times would literally explode with eager semantic
> analysis.
>

As HS Teoh explained, this could actually be done at very little cost for
symbol scope resolution. It is done once per template.

Reply via email to