2215 – Forward reference enum with base type within a struct causes Segmentation Fault in the compiler

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2215 - Forward reference enum with base type within a struct causes Segmentation Fault in the compiler
Summary: Forward reference enum with base type within a struct causes Segmentation Fau...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P2 major
Assignee: Walter Bright
URL:
Keywords: ice-on-valid-code
: 2290 (view as issue list)
Depends on:
Blocks: 340
Show dependency tree / graph
Reported: 2008年07月10日 13:32 UTC by Steven Schveighoffer
Modified: 2015年06月09日 01:19 UTC (History)
3 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Steven Schveighoffer 2008年07月10日 13:32:22 UTC
This code causes a dmd segmentation fault:
struct S
{
 E e;
}
enum E : int
{
 E1
}
replace int with ubyte, also fails. I think this should be valid code because moving e outside the struct or putting it in a class works (no errors, no segfault).
The workaround is to declare the enum first.
Comment 1 Steven Schveighoffer 2008年08月19日 09:04:43 UTC
*** Bug 2290 has been marked as a duplicate of this bug. ***
Comment 2 Don 2009年04月02日 14:52:56 UTC
This is segfaulting in mtype.c, line 5156. If the enum is forward referenced, it doesn't know if it's default-initialised, so defaultval is null -> segfault. 
int TypeEnum::isZeroInit()
{
 return sym->defaultval->isBool(FALSE);
}
Unfortunately, 'loc' is not a parameter to isZeroInit, so I don't know how to give an error msg with missing line number.
There are actually two other places in TypeEnum where this problems happens:
isunsigned() uses memtype without checking.
hasPointers() uses toBaseType() without checking.
alignsize() probably gives error message without line number.
Comment 3 Don 2009年05月14日 07:27:38 UTC
Fixed DMD2.030.


AltStyle によって変換されたページ (->オリジナル) /