diff --git a/std/variant.d b/std/variant.d index 5622163af..52f554451 100644 --- a/std/variant.d +++ b/std/variant.d @@ -514,10 +514,16 @@ private: { t[i] = variantArgs[i].get!T(); } + static if(is(ReturnType!A == void)) + { + (*zis)(t.expand); *p = VariantN.init; // Uninitialized Variant.Uninitialized + } else + { *p = (*zis)(t.expand); + } } break; @@ -1643,6 +1649,18 @@ unittest assertThrown!VariantException(Variant(A(3)) < Variant(A(4))); } +// Handling of void function pointers / delegates, e.g. issue 11360 +unittest +{ + static void t1() { } + Variant v = &t1; + assert(v() == Variant.init); + + static int t2() { return 3; } + Variant v2 = &t2; + assert(v2() == 3); +} + /** * Applies a delegate or function to the given Algebraic depending on the held type, * ensuring that all types are handled by the visiting functions.