Bug 7732 – [CTFE] wrong code for a struct called AssociativeArray
Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-03-19T07:55:00Z
Last change time
2012-03-20T14:06:10Z
Keywords
wrong-code
Assigned to
nobody
Creator
hsteoh
Comments
Comment #0 by hsteoh — 2012-03-19T07:55:54Z
Something is BADLY broken with CTFE:
struct AssociativeArray
{
int *impl;
int f()
{
if (impl !is null)
auto x = *impl; // this is line 7
return 1;
}
}
void main() {
int test()
{
AssociativeArray aa;
return aa.f;
}
enum str = test();
}
This is not a fully minimized test case, but I've tried my best to reduce it as
much as possible. With the latest dmd from git, this gives:
test.d(7): Error: dereference of invalid pointer 'AssociativeArray(null)'
test.d(15): called from here: aa.f()
test.d(17): called from here: test()
This is a VERY serious bug because apparently the condition (impl !is null)
actually passes, even though impl is null!
This appears to be related to the current AssociativeArray magic (renaming the
struct in the above code makes the bug go away).
Comment #1 by clugdbug — 2012-03-19T23:31:21Z
This is very obscure, I don't think anybody else will ever encounter this. But it's an easy fix.
Comment #2 by github-bugzilla — 2012-03-20T13:39:28Z