question...
Aarti_pl
aarti at interia.pl
Wed Jan 9 04:17:46 PST 2008
Daniel919 pisze:
>> void main() {
>> class A {}
>> static assert(is( typeof(new A) == typeof(A)) ); // 1
>> static assert(is( typeof(new int*) == typeof(int*) )); // 2
>> }
>>
>> First assert compiles, but the second one not.
>
> It's because of the difference that
> - classes are reference types
> - basic data types and structs are value types
>
>
> These are working:
>
> //reference type
> class A {}
> static assert(is( typeof(new A) == A ));
>
>
> //value type
> struct B {}
> static assert(is( typeof(new B) == B* ));
>
> static assert(is( typeof(new int) == int* ));
> static assert(is( typeof(new int*) == int** ));
Yes, sure. I missed one asterisk in second assert.
But I think that it is compiler bug that second assert in my example
(with typeof(int**)) doesn't compile at all. At least on my computer
with DMD 1.025, while it is IMHO perfectly correct.
What's more error message is completely misleading:
quicktest.d(62): found '*' when expecting '.' following 'int'
quicktest.d(62): found ')' when expecting identifier following 'int.'
quicktest.d(62): found ';' when expecting ')'
quicktest.d(64): found '}' when expecting ';'
quicktest.d(65): found 'EOF' instead of statement
quicktest.d(65): found 'EOF' instead of statement
quicktest.d(65): found 'EOF' instead of statement
I will probably report it as a bug. While it has not so much sense to
do: typeof(int**) it should nevertheless work as expected or at least
report proper error.
BR
Marcin Kuszczak
More information about the Digitalmars-d-learn
mailing list