diff --git a/src/dmd/dinterpret.d b/src/dmd/dinterpret.d index 1ab0c6d502ef..831c409404e4 100644 --- a/src/dmd/dinterpret.d +++ b/src/dmd/dinterpret.d @@ -4262,6 +4262,13 @@ public: lowerbound = 0; upperbound = 0; } + else if (VectorExp ve = e1.isVectorExp()) + { + // ve is not handled but a proper error message is returned + // this is to prevent https://issues.dlang.org/show_bug.cgi?id=20042 + lowerbound = 0; + upperbound = ve.dim; + } else assert(0); diff --git a/test/fail_compilation/ice20042.d b/test/fail_compilation/ice20042.d new file mode 100644 index 000000000000..7ba9309c0772 --- /dev/null +++ b/test/fail_compilation/ice20042.d @@ -0,0 +1,29 @@ +/* +DISABLED: freebsd32 linux32 osx32 win32 +TEST_OUTPUT: +--- +fail_compilation/ice20042.d(18): Error: slice operation `cast(__vector(float[4]))nanF = [1.00000F, 2.00000F, 3.00000F, 4.00000F][0..4]` cannot be evaluated at compile time +fail_compilation/ice20042.d(25): called from here: `Vec4(cast(__vector(float[4]))[nanF, nanF, nanF, nanF]).this([1.00000F, 2.00000F, 3.00000F, 4.00000F])` +--- +*/ +void write(T...)(T t){} + +struct Vec4 +{ + __vector(float[4]) raw; + + this(const(float[4]) value...) inout pure @safe nothrow @nogc + { + __vector(float[4]) raw; + raw[] = value[]; + this.raw = raw; + } +} + +void main() +{ + static immutable Vec4 v = Vec4( 1.0f, 2.0f, 3.0f, 4.0f ); + + static foreach(d; 0 .. 4) + write(v.raw[d], " "); +}