-
-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zero-length static array is null, unlike in dmd #831
Comments
|
I don't think this is a valid issue. Zero-length objects aren't required to have an address by the spec, as far as I can see. Do you have any relevant spec references? |
|
(We can't really make zero-size allocations in LLVM, we'd have to use at least one byte.) |
|
Hm, if this is accurate http://wiki.dlang.org/LDC-specific_language_changes#Zero-length_static_arrays it suggests that LDC did at some point do the one-byte allocation to give it an address? |
|
The contents of this wiki page are ancient, unfortunately, as it was copied over from the dsource LDC1 page. I just removed the statement in question, as I couldn't find any relevant parts in the spec. http://dlang.org/arrays.html only has
which LDC seems to follow just fine. If you find anything more definitive, please let me know. You might also want to bring this up on the main D newsgroup or dmd-internals, so we can work out a properly specified behavior (or add an explanatory comment in the spec). |
|
Requested comments at http://forum.dlang.org/thread/zfwykmybraqxcciwsrgu@forum.dlang.org . |
|
Thanks for pinging me, I missed the forum thread. See my replies there. |
LDC treats zero-length arrays differently from dmd:
void test(int[] data)
in { assert(data, "data must be non-null."); }
body { }
void main() {
import std.stdio;
int[1] data1;
writeln(data1); // [0]
test(data1); // Passes
int[0] data0;
writeln(data0); // []
test(data0); // Passes with dmd 2.066.1, asserts with ldc2 0.15.1
}
The text was updated successfully, but these errors were encountered: