finding errors with templates without instantiating them
Andrej Mitrovic
andrej.mitrovich at gmail.com
Thu Sep 5 10:41:14 PDT 2013
On 9/5/13, Timothee Cour <thelastmammoth at 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
}
-----
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.
More information about the Digitalmars-d
mailing list