Thread overview | ||||||
---|---|---|---|---|---|---|
|
October 13, 2013 [Issue 11247] New: Error: typeof(i).sizeof is used as a type | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=11247 Summary: Error: typeof(i).sizeof is used as a type Product: D Version: unspecified Platform: All OS/Version: All Status: NEW Keywords: rejects-valid Severity: normal Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: monarchdodra@gmail.com --- Comment #0 from monarchdodra@gmail.com 2013-10-13 13:15:22 PDT --- Not sure what to make of this: //---- void main() { int i; //This is OK: enum N = typeof(i).sizeof; byte[N] a; //This is also OK: byte[int.sizeof] b; //This errors out byte[typeof(i).sizeof] b; } //---- Error: typeof(i).sizeof is used as a type //---- I *think* the compiler thinks I'm declaring an AA (When I want a SA) ? FYIW, in 2.062 and prior, the error message is: Error: cannot resolve .property for typeof(i).sizeof -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 13, 2013 [Issue 11247] Error: typeof(i).sizeof is used as a type | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarchdodra@gmail.com | http://d.puremagic.com/issues/show_bug.cgi?id=11247 Maxim Fomin <maxim@maxim-fomin.ru> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |maxim@maxim-fomin.ru --- Comment #1 from Maxim Fomin <maxim@maxim-fomin.ru> 2013-10-13 14:13:01 PDT --- (In reply to comment #0) > Not sure what to make of this: > > //---- > void main() > { > int i; > > //This is OK: > enum N = typeof(i).sizeof; > byte[N] a; > > //This is also OK: > byte[int.sizeof] b; > > //This errors out > byte[typeof(i).sizeof] b; > } > //---- > Error: typeof(i).sizeof is used as a type > //---- > > I *think* the compiler thinks I'm declaring an AA (When I want a SA) ? Of course you are declaring AA here because D does not support variable arrays like C. Sizeof property in this context is treated as type, not expression - that's why sizeof yileds ulong, not 4. If you wanted to have static array here, then this is invalid report. However, if you want this to compile as AA array, than this is really rejects-valid. On the other hand, this is useless - in such cases Foo[bar.sizeof] always yileds Foo[ulong]. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 13, 2013 [Issue 11247] Error: typeof(i).sizeof is used as a type | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarchdodra@gmail.com | http://d.puremagic.com/issues/show_bug.cgi?id=11247 --- Comment #2 from monarchdodra@gmail.com 2013-10-13 14:20:47 PDT --- (In reply to comment #1) > (In reply to comment #0) > > Not sure what to make of this: > > > > //---- > > void main() > > { > > int i; > > > > //This is OK: > > enum N = typeof(i).sizeof; > > byte[N] a; > > > > //This is also OK: > > byte[int.sizeof] b; > > > > //This errors out > > byte[typeof(i).sizeof] b; > > } > > //---- > > Error: typeof(i).sizeof is used as a type > > //---- > > > > I *think* the compiler thinks I'm declaring an AA (When I want a SA) ? > > Of course you are declaring AA here because D does not support variable arrays like C. sizeof is a compile time constant though... so it's not a variable size array. EG: byte[int.sizeof] b; static sized array. > Sizeof property in this context is treated as type, not expression Why? byte[int.sizeof] b; Here, it's treated correctly. it's the "typeof" that is throwing it off. > that's why sizeof yileds ulong, not 4. sizeof can yield a *type*? That's news to me. > If you wanted to have static array here, then this is invalid report. However, if you want this to compile as AA array, than this is really rejects-valid. On the other hand, this is useless - in such cases Foo[bar.sizeof] always yileds Foo[ulong]. I *really* don't understand how: byte[int.sizeof] b; byte[typeof(i).sizeof] c; Could have two different behaviors... -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 13, 2013 [Issue 11247] Error: typeof(i).sizeof is used as a type | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarchdodra@gmail.com | http://d.puremagic.com/issues/show_bug.cgi?id=11247 --- Comment #3 from Maxim Fomin <maxim@maxim-fomin.ru> 2013-10-13 14:33:57 PDT --- (In reply to comment #2) > (In reply to comment #1) > > (In reply to comment #0) > > > Not sure what to make of this: > > > > > > //---- > > > void main() > > > { > > > int i; > > > > > > //This is OK: > > > enum N = typeof(i).sizeof; > > > byte[N] a; > > > > > > //This is also OK: > > > byte[int.sizeof] b; > > > > > > //This errors out > > > byte[typeof(i).sizeof] b; > > > } > > > //---- > > > Error: typeof(i).sizeof is used as a type > > > //---- > > > > > > I *think* the compiler thinks I'm declaring an AA (When I want a SA) ? > > > > Of course you are declaring AA here because D does not support variable arrays like C. > > sizeof is a compile time constant though... so it's not a variable size array. > EG: > byte[int.sizeof] b; > static sized array. > > > Sizeof property in this context is treated as type, not expression > > Why? > byte[int.sizeof] b; > Here, it's treated correctly. it's the "typeof" that is throwing it off. It looks like it is undocumented whether sizeof should yield ulong or 4 here. > > > that's why sizeof yileds ulong, not 4. > > sizeof can yield a *type*? That's news to me. > > > If you wanted to have static array here, then this is invalid report. However, if you want this to compile as AA array, than this is really rejects-valid. On the other hand, this is useless - in such cases Foo[bar.sizeof] always yileds Foo[ulong]. > > I *really* don't understand how: > byte[int.sizeof] b; > byte[typeof(i).sizeof] c; > Could have two different behaviors... Yes, they should be same. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation