[dmd-beta] dmd 1.062 and 2.047 beta
Rainer Schuetze
r.sagitario at gmx.de
Sat Jun 12 01:38:19 PDT 2010
Hi,
this is what happens:
while deducing a template match,
- a template instance of binaryFunImpl!false is created to evaluate
is(binaryFunImpl!(false).ReturnType)
- the template instance is added as a member to the module
- semantic analysis fails, so the respective startsWith alternative is
rejected
- compiler attempts to compile added binaryFunImpl!false and fails
so it helps to write
template binaryFunImpl(bool b)
if(b)
{
...
avoiding creation of the template instance, but I was not able to add a
similar test to startsWith in std.algorithm. Maybe someone else has an
idea how to do it?
Though this is kind of a blocker for me, should I add just add it as a
regression to bugzilla?
Rainer
Rainer Schuetze wrote:
> Hi,
>
> I've tried to untangle the startsWith code, and here's the minimal
> test case I could come up with so far:
>
> ///////////////////////
> template binaryFunImpl(bool b)
> {
> template Body()
> {
> static assert(b);
> alias bool BodyType;
> }
> alias Body!().BodyType ReturnType; // line 9
> }
>
> uint startsWith(A)(A a) if (is(binaryFunImpl!(true ).ReturnType)) {
> return 1; }
> uint startsWith(A)(A a) if (is(binaryFunImpl!(false).ReturnType)) {
> return 0; } // line 13
>
> const uint var = startsWith(1);
> ///////////////////////
> dmd produces:
>
> test.d(6): Error: static assert (b) is false
> test.d(9): instantiated from here: Body!()
> test.d(13): instantiated from here: binaryFunImpl!(false)
>
> The error does not show up if var is not const. Also, dmd 2.032 to
> 2.045 do not produce this error (2.046 fails), so it must be some
> compiler regression.
>
> As it seems, the compile time evaluation of startsWith uses the wrong
> specialization. Maybe, it is just not gagging error output?
>
> Any other ideas? I have not yet dived too deep into the template code
> of the compiler, but if nobody has a better clue (and time), I can
> give it a try.
More information about the dmd-beta
mailing list