DMD 1.033 (typeof() error instantiating in template)

Koroskin Denis 2korden at gmail.com
Thu Jul 17 07:39:12 PDT 2008


On Thu, 17 Jul 2008 17:59:35 +0400, David L. Davis  
<SpottedTiger at yahoo.com> wrote:

> Walter Bright Wrote:
>
>> For Tango.
>>
>> http://www.digitalmars.com/d/1.0/changelog.html
>> http://ftp.digitalmars.com/dmd.1.033.zip
>>
>
> Walter,
>
>      I've discovered a piece of my D 1.xxx source that's now broken  
> since the dmd v1.033/v1.032 release...below is the test code to show the  
> error(s).
>
> // Test source typeofx.d to recreate the error
> module typeofx;
>
> private import sc = std.compiler;
> private import std.stdio;
> private import std.stdarg;
>
> // Setup TypeoF const types
> const uint  TF_UINT;
> const ulong TF_ULONG;
>
> template isIntConvertableP(T1, T2)
> {
>      private bool isIntConvertableP(in T1 v)
>      {
> 	     if (typeid(T1) !is typeid(int))
> 	         return false;
> 	
>          typeof(T2) v2;
>         writefln("T1.typid=%s, T1.v=", typeid(T1), v,
>                     " T1.tsize=%d, ", T1.sizeof,
>                     "T2.typid=%s, T2.tsize=%d", typeid(T2), T2.sizeof);
>
>          if (v >= v2.min && v <= v2.max)
>              return true;	
>          else
>              return false;
>      }
> }
>
> bool isIntConvertable(...)
> {
>     if (_arguments.length < 2)
>         return false;
>    TypeInfo ti1 = _arguments[0];
>     TypeInfo ti2 = _arguments[1];
>    int i = (va_arg!(int)(_argptr));
>    if (ti2 is typeid(ulong))
>         return isIntConvertableP!(int, ulong)(i);
>    if (ti2 is typeid(uint))
>         return isIntConvertableP!(int, uint)(i);
>    return false;
> }
>
> int main()
> {
>     // works for dmd v1.031,
>     // doesn't work under v1.033/v1.032
>     assert(isIntConvertableP!(int, ulong)(123) == true);
> 	
>     // works for dmd v1.031,
>     //doesn't work under v1.033/v1.032
>     assert(isIntConvertable(123, TF_ULONG) == true);
>
>     writefln();
>     writefln("Compiled and tested with: \"%s v%d.%03d\"",
>                  sc.name, sc.version_major, sc.version_minor);
> 	
>     return 0;
> }
>
> /+ compile and run with dmd v1.031
> C:\dmd>dmd typeofx.d
> C:\dmd>typeofx
> T1.typid=int, T1.v=123 T1.tsize=4, T2.typid=ulong, T2.tsize=8
> T1.typid=int, T1.v=123 T1.tsize=4, T2.typid=ulong, T2.tsize=8
> Compiled and tested with: "Digital Mars D v1.031"
> C:\dmd>
> +/
>
> /+ dmd v1.033/1.032 gotten with the 1st assert
> C:\dmd>dmd typeofx.d
> typeofx.d(18): Error: argument ulong to typeof is not an expression
> typeofx.d(42): template instance typeofx.isIntConvertableP!(int,ulong)  
> error instantiating
>
> C:\dmd>
> +/
>
> /+  dmd v1.033/1.032 gotten with the 2nd assert...1st assert commented in
> C:\dmd>dmd typeofx.d
> typeofx.d(18): Error: argument ulong to typeof is not an expression
> typeofx.d(42): template instance typeofx.isIntConvertableP!(int,ulong)   
> error instantiating
>
> C:\dmd>
> +/
>
> Thanks,
> David L. Davis


typeof(T2) doesn't work anymore. Try replacing with T2.
BTW, error message is pretty clear and shows correct line number.

typeof(T2) v2; // Error: argument ulong to typeof is not an expression

Next time post to digitalmars.D or digitalmars.D.learn, please!


More information about the Digitalmars-d-announce mailing list