Skip to content
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

Open
SFrijters opened this issue Jan 27, 2015 · 6 comments
Open

Zero-length static array is null, unlike in dmd #831

SFrijters opened this issue Jan 27, 2015 · 6 comments

Comments

@SFrijters
Copy link

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
}

@dnadlinger
Copy link
Member

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?

@dnadlinger
Copy link
Member

(We can't really make zero-size allocations in LLVM, we'd have to use at least one byte.)

@SFrijters
Copy link
Author

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?

@dnadlinger
Copy link
Member

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

A static array with a dimension of 0 is allowed, but no space is allocated for it.

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).

@SFrijters
Copy link
Author

@dnadlinger dnadlinger changed the title Zero-length array is null, unlike in dmd Zero-length static array is null, unlike in dmd Feb 4, 2015
@dnadlinger
Copy link
Member

Thanks for pinging me, I missed the forum thread. See my replies there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants