[Issue 9539] Regression (2.061): Wrong-code on static array pointer
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Feb 20 23:48:02 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9539
--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> 2013-02-20 23:48:00 PST ---
(In reply to comment #0)
> void f(int** ptr)
> {
> assert(**ptr == 10);
> }
>
> void main()
> {
> int* i = new int;
> *i = 10;
> int*[1] x = [i];
> f(&x[0]);
> }
More simple case:
int*[1] x;
int* p = new int;
x = [p]; // is wrongly rewritten to: x[] = [p].ptr
printf("p = %p, x[0] = %p\n", p, x[0]);
assert(p == x[0]); // fails!?
----
This is horribly serious problem.
The root issue is in TypeDArray::implicitConvTo. FROM THE BEGINNING of D2, an
implicit conversion from dynamic array to its element pointer type as a
deprecated feature.
int[] arr; int* p;
p = arr; // is expected to rewrite to p = arr.ptr
BUT, it was completely broken FROM THE BEGINNING of D2. Instead of the expected
behavior, dynamic array can be convertible to its element type.
int*[] arr = [null];
int* p;
p = arr; // bad!
printf("p = %p, arr.ptr = %p\n", p, arr.ptr);
It has been wrongly accepted in long time if '-d' switch is specified. Then,
from 2.061, the situation has become worse by "informational deprecated error
in default". Above code would be _silently_ accepted in default, and compiler
outputs wrong-code.
----
But, we cannot *fix* TypeDArray::implicitConvTo to implement the deprecated
feature, because it breaks phobos building.
In std.process line 367:
scope(exit) if (exists(filename)) remove(filename); // <----
Today, it calls std.file.remove in here.
std.stdio.file line 413:
void remove(in char[] name)
But std.process also imports core.stdc.stdio through std.stdio. In there
another 'remove' is defined.
core.stdc.stdio line 453:
int remove(in char* filename); // <----
After *fixing* the deprecated feature, the 'remove' call in std.process will
match both 'remove's that defined in different modules, and it will raise an
error according to overload set resolution rule.
std\process.d(367): Error: std.file.remove at std\file.d(413) conflicts with
core.stdc.stdio.remove at
C:\Users\khara\dmd2\src\druntime\import\core\stdc\stdio.d(453)
----
So as a conclusion, we should just remove the deprecated "array to pointer
conversion" feature, rather than fixing broken deprecated feature that already
outdated.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list