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

Issue 4539 - Refuse assignment to string literal #46

Merged
merged 1 commit into from
Jun 5, 2011

Conversation

9rnsr
Copy link
Contributor

@9rnsr 9rnsr commented Apr 27, 2011

This change might not be enhancement, but breaks existing code.

WalterBright added a commit that referenced this pull request Jun 5, 2011
Issue 4539 - Refuse assignment to string literal
@WalterBright WalterBright merged commit 083443d into dlang:master Jun 5, 2011
@WalterBright
Copy link
Member

Needs more work, fails the following from xtest46.d:

void test69()
{
digestToString69(cast(ubyte[16])x"c3fcd3d76192e4007dfb496cca67e13b");
}

void digestToString69(ref const ubyte[16] digest)
{
assert(digest[0] == 0xc3);
assert(digest[15] == 0x3b);
}

/***************************************************/

void test70()
{
digestToString70("1234567890123456");
}

void digestToString70(ref const char[16] digest)
{
assert(digest[0] == '1');
assert(digest[15] == '6');
}

Reverted for now.

@9rnsr
Copy link
Contributor Author

9rnsr commented Jun 5, 2011

I think ref parameter should not receive string literal, because it is rvalue.
Now dmd treats array literal (not string) as rvalue, so following code is invalid:
void f(ref int[] arr){...}
f([1,2]); // rejected

Does D specification treat string against ref parameter as special case?
If not, this changes valid and test suite is invalid.

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

Successfully merging this pull request may close these issues.

2 participants