Skip to content

Commit

Permalink
Merge pull request #7701 from ibuclaw/fix18507
Browse files Browse the repository at this point in the history
fix Issue 18057 - [ICE] Segmentation fault (stack overflow) in Expression::ctfeInterpret()
merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>
  • Loading branch information
dlang-bot authored Jan 14, 2018
2 parents 07bbd0a + 5e066ee commit 74285e4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/dmd/aggregate.d
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,13 @@ extern (C++) abstract class AggregateDeclaration : ScopeDsymbol
else if (vx._init)
{
assert(!vx._init.isVoidInitializer());
e = vx.getConstInitializer(false);
if (vx.inuse) // https://issues.dlang.org/show_bug.cgi?id=18057
{
vx.error(loc, "recursive initialization of field");
errors = true;
}
else
e = vx.getConstInitializer(false);
}
else
{
Expand Down
11 changes: 11 additions & 0 deletions test/compilable/interpret3.d
Original file line number Diff line number Diff line change
Expand Up @@ -7731,3 +7731,14 @@ bool foo17407()

static assert(!foo17407);

/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=18057
// Recursive field initializer causes segfault.

struct RBNode(T)
{
RBNode!T *copy = new RBNode!T;
}

static assert(!__traits(compiles, { alias bug18057 = RBNode!int; }));

16 changes: 16 additions & 0 deletions test/fail_compilation/fail18057.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
TEST_OUTPUT:
---
fail_compilation/fail18057.d(16): Error: template instance RBNode!int `RBNode` is not a template declaration, it is a struct
fail_compilation/fail18057.d(13): Error: variable fail18057.RBNode.copy recursive initialization of field
---
*/

// https://issues.dlang.org/show_bug.cgi?id=18057
// Recursive field initializer causes segfault.
struct RBNode
{
RBNode *copy = new RBNode;
}

alias bug18057 = RBNode!int;

0 comments on commit 74285e4

Please sign in to comment.