@@ -850,7 +850,14 @@ public:
850
850
*/
851
851
@property inout (T) get (T)() inout
852
852
{
853
- inout (T) result = void ;
853
+ static union SupressDestructor {
854
+ T val;
855
+ }
856
+
857
+ /* If this function fails and it throws, copy elision will not run and the destructor might be called.
858
+ * But since this value is void initialized, this is undesireable.
859
+ */
860
+ inout (SupressDestructor) result = void ;
854
861
static if (is (T == shared ))
855
862
alias R = shared Unqual! T;
856
863
else
@@ -861,7 +868,7 @@ public:
861
868
{
862
869
throw new VariantException(type, typeid (T));
863
870
}
864
- return result;
871
+ return result.val ;
865
872
}
866
873
867
874
// / Ditto
@@ -3256,7 +3263,7 @@ if (isAlgebraic!VariantType && Handler.length > 0)
3256
3263
auto v = Variant (aa); // compile error
3257
3264
}
3258
3265
3259
- // https://issues. dlang.org/show_bug.cgi?id=8195
3266
+ // https://github.com/ dlang/phobos/issues/9585
3260
3267
// Verify that alignment is respected
3261
3268
@safe unittest
3262
3269
{
@@ -3268,3 +3275,31 @@ if (isAlgebraic!VariantType && Handler.length > 0)
3268
3275
enum FP_SIZE = (int function ()).sizeof;
3269
3276
static assert (AFoo1.sizeof >= double .sizeof + FP_SIZE );
3270
3277
}
3278
+
3279
+ // https://github.com/dlang/phobos/issues/10518
3280
+ @system unittest
3281
+ {
3282
+ import std.exception : assertThrown;
3283
+
3284
+ struct Huge {
3285
+ real a, b, c, d, e, f, g;
3286
+ }
3287
+ Huge h = {1 ,1 ,1 ,1 ,1 ,1 ,1 };
3288
+ Variant variant = Variant ([
3289
+ " one" : Variant (1 ),
3290
+ ]);
3291
+ // Testing that this doesn't segfault. Future work might make enable this
3292
+ assertThrown! VariantException(variant[" three" ] = 3 );
3293
+ assertThrown! VariantException(variant[" four" ] = Variant (4 ));
3294
+ /* Storing huge works too, value will moved to the heap
3295
+ * Testing this as a regression test here as the AA handling code is still somewhat brittle and might add changes
3296
+ * that depend payload size in the future
3297
+ */
3298
+ assertThrown! VariantException(variant[" huge" ] = Variant (h));
3299
+ /+
3300
+ assert(variant["one"] == Variant(1));
3301
+ assert(variant["three"] == Variant(3));
3302
+ assert(variant["three"] == 3);
3303
+ assert(variant["huge"] == Variant(h));
3304
+ +/
3305
+ }
0 commit comments