571 – class instance member template returns strange value

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 571 - class instance member template returns strange value
Summary: class instance member template returns strange value
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: Walter Bright
URL:
Keywords: wrong-code
Depends on:
Blocks:
Reported: 2006年11月19日 01:39 UTC by Nazo Humei
Modified: 2015年06月09日 05:14 UTC (History)
1 user (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Nazo Humei 2006年11月19日 01:39:16 UTC
class Test{
 template test(){
 const int test=1;
 }
}
void main(){
 assert(Test.test!()==1);//ok
 assert((new Test).test!()==1);//failed
}
Comment 1 Thomas Kühne 2006年11月25日 07:50:54 UTC
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
d-bugmail@puremagic.com 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 Walter Bright 2008年06月29日 20:53:05 UTC
This is invalid code in D 2.0, as templates cannot be used to add fields to a class.
Comment 3 Koroskin Denis 2008年06月30日 05:39:00 UTC
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 Walter Bright 2008年07月09日 22:36:20 UTC
Fixed dmd 1.032 and 2.016


AltStyle によって変換されたページ (->オリジナル) /