Bug 571 – class instance member template returns strange value

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2006-11-19T01:39:00Z
Last change time
2015-06-09T05:14:55Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
lovesyao

Comments

Comment #0 by lovesyao — 2006-11-19T01:39:16Z
class Test{ template test(){ const int test=1; } } void main(){ assert(Test.test!()==1);//ok assert((new Test).test!()==1);//failed }
Comment #1 by thomas-dloop — 2006-11-25T07:50:54Z
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [email protected] schrieb am 2006-11-19: > http://d.puremagic.com/issues/show_bug.cgi?id=571 > class Test{ > template test(){ > const int test=1; > } > } > > void main(){ > assert(Test.test!()==1);//ok > assert((new Test).test!()==1);//failed > } Added to DStress as http://dstress.kuehne.cn/run/t/template_47_A.d http://dstress.kuehne.cn/run/t/template_47_B.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFFaEqHLK5blCcjpWoRAgCJAJ9dZUpUeaSP0QBXBufU/RlYeYqjAwCglpP4 IY/UQZYAOBYmlU3lVwDvuCE= =pw18 -----END PGP SIGNATURE-----
Comment #2 by bugzilla — 2008-06-29T20:53:05Z
This is invalid code in D 2.0, as templates cannot be used to add fields to a class.
Comment #3 by 2korden — 2008-06-30T05:39:00Z
Updated test case for D2: class Test { template test(){ enum int test = 1; // replace with const for D1 } } void main(){ printf("%d", (new Test()).test!()); }
Comment #4 by bugzilla — 2008-07-09T22:36:20Z
Fixed dmd 1.032 and 2.016