diff --git a/std/algorithm.d b/std/algorithm.d index 0d62bc010..61e769e42 100644 --- a/std/algorithm.d +++ b/std/algorithm.d @@ -13308,6 +13308,8 @@ When there are more than two ranges, the above conditions apply to each adjacent pair of ranges. */ auto cartesianProduct(R1, R2)(R1 range1, R2 range2) + if (!allSatisfy!(isForwardRange, R1, R2) || + anySatisfy!(isInfinite, R1, R2)) { static if (isInfinite!R1 && isInfinite!R2) { @@ -13536,9 +13538,17 @@ unittest } } +// Issue 13091 +pure nothrow @safe @nogc unittest +{ + import std.algorithm: cartesianProduct; + int[1] a = [1]; + foreach (t; cartesianProduct(a[], a[])) {} +} + /// ditto auto cartesianProduct(RR...)(RR ranges) - if (ranges.length > 2 && + if (ranges.length >= 2 && allSatisfy!(isForwardRange, RR) && !anySatisfy!(isInfinite, RR)) {