From 265e42a2bf63a89f27878fada44e9eb7892e319b Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Sun, 14 Jan 2018 00:25:48 +0100 Subject: [PATCH] fix Issue 18057 - [ICE] Segmentation fault (stack overflow) in Expression::ctfeInterpret() --- src/dmd/aggregate.d | 8 +++++++- test/compilable/interpret3.d | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/dmd/aggregate.d b/src/dmd/aggregate.d index eb1e9f35d116..f2453c50c998 100644 --- a/src/dmd/aggregate.d +++ b/src/dmd/aggregate.d @@ -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 { diff --git a/test/compilable/interpret3.d b/test/compilable/interpret3.d index 8e7025c7f59f..386743e6ddc4 100644 --- a/test/compilable/interpret3.d +++ b/test/compilable/interpret3.d @@ -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; })); +