Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2977 from 9rnsr/fix11756
Issue 11756 - Irrelevant variable name printing in CTFE error message
- Loading branch information
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
TEST_OUTPUT: | ||
--- | ||
fail_compilation/diag11756.d(15): Error: cannot read uninitialized variable cnt in CTFE | ||
fail_compilation/diag11756.d(34): called from here: foo.ptr2.opAssign(Ptr(& n)) | ||
fail_compilation/diag11756.d(39): called from here: test() | ||
fail_compilation/diag11756.d(39): while evaluating: static assert(test()) | ||
--- | ||
*/ | ||
|
||
struct Ptr | ||
{ | ||
void opAssign(Ptr other) | ||
{ | ||
(*cnt)--; // error | ||
cnt = other.cnt; | ||
(*cnt)++; | ||
} | ||
size_t *cnt; | ||
} | ||
|
||
union Foo | ||
{ | ||
size_t *ptr1; | ||
Ptr ptr2; | ||
} | ||
|
||
bool test() | ||
{ | ||
Foo foo; | ||
size_t cnt = 1; | ||
foo.ptr1 = &cnt; | ||
size_t n; | ||
foo.ptr2 = Ptr(&n); | ||
assert(cnt == 0); | ||
|
||
return true; | ||
} | ||
static assert(test()); |