d: Merge upstream dmd, druntime 4c18eed967, phobos d945686a4.
[official-gcc.git] / gcc / testsuite / gdc.test / fail_compilation / fail19038.d
blobef1a8b767e5b9a1e450aada5c1541469a9f5056d
1 /* TEST_OUTPUT:
2 ---
3 fail_compilation/fail19038.d(21): Error: cannot implicitly convert expression `a` of type `string[][]` to `const(string)[][]`
4 fail_compilation/fail19038.d(23): Error: cannot modify `const` expression `c[0]`
5 ---
6 * Credit: yshui
7 * https://github.com/dlang/dmd/pull/8413#issuecomment-401104961
8 * https://issues.dlang.org/show_bug.cgi?id=19038
9 */
12 void test()
14 /* string[][] is not implicitly converible to const(string)[][],
15 * and there is good reason why:
17 * https://stackoverflow.com/questions/5055655/double-pointer-const-correctness-warnings-in-c
20 string[][] a = [["Lord"]];
21 const(string)[][] b = a; // assume this works (and it should not)
22 const(string)[] c = ["Sauron"];
23 c[0] = "Mordor"; // invalid, because c[0] is const(string)
25 b[0] = c; // valid, b[0] is const(string)[]
26 // But now, a[0] has become c
27 a[0][0] = "Nazgul"; // valid, because a[0][0] is string
28 // But this also changes c[0], which shouldn't be possible