digitalmars.D.bugs - const is not treated as const!
- no where.com Apr 23 2005
- zwang <nehzgnaw gmail.com> Apr 23 2005
- no where.com Apr 23 2005
- Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> Apr 24 2005
$ cat a.d
template T(int N) {
int[N] array;
}
const int x = 2;
const int y = x * x;
mixin T!(y);
$ dmd -c a.d
a.d(9): Integer constant expression expected instead of x * x
Since y is decl-ed as const, its value is known at compile time.
Apr 23 2005
no where.com wrote:$ cat a.d template T(int N) { int[N] array; } const int x = 2; const int y = x * x; mixin T!(y); $ dmd -c a.d a.d(9): Integer constant expression expected instead of x * x Since y is decl-ed as const, its value is known at compile time.
Although constant propagation and constant folding are nice, yet I don't think it is a bug if the compiler misses some optimizing opportunities. Consider an extreme case: const double x = cast(double)rand(); const double y = cos(x)*cos(x)+sin(x)*sin(x); y is obviously 1.0, but it's not that obvious to all the compilers I have used.
Apr 23 2005
$ cat a.d
template T(int N) {
int[N] array;
}
const int x = 2;
const int y = x * x;
int[y] why_here_it_works;
//mixin T!(y);
$ dmd -c a.d
$ ls a.o
a.o
In article <d4f8uv$16q$1 digitaldaemon.com>, zwang says...
no where.com wrote:
$ cat a.d
template T(int N) {
int[N] array;
}
const int x = 2;
const int y = x * x;
mixin T!(y);
$ dmd -c a.d
a.d(9): Integer constant expression expected instead of x * x
Since y is decl-ed as const, its value is known at compile time.
Although constant propagation and constant folding are nice,
yet I don't think it is a bug if the compiler misses some
optimizing opportunities.
Consider an extreme case:
const double x = cast(double)rand();
const double y = cos(x)*cos(x)+sin(x)*sin(x);
y is obviously 1.0, but it's not that obvious to all the compilers
I have used.
Apr 23 2005
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 no where.com schrieb am Sun, 24 Apr 2005 02:40:15 +0000 (UTC):$ cat a.d template T(int N) { int[N] array; } const int x = 2; const int y = x * x; mixin T!(y); $ dmd -c a.d a.d(9): Integer constant expression expected instead of x * x Since y is decl-ed as const, its value is known at compile time.
Added to DStress as http://dstress.kuehne.cn/run/const_18.d http://dstress.kuehne.cn/run/const_19.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCbIcl3w+/yD4P9tIRAnE+AJ4/SElBVafvCIzmbM77EsXylJvY3ACfTph1 JnxP+LHqsHHF10O3YbUmEgI= =jE16 -----END PGP SIGNATURE-----
Apr 24 2005









no where.com 