@@ -2648,16 +2648,19 @@ if (!Init.length ||
26482648}
26492649
26502650/**
2651- * Allocate an exception of type `T` from the exception pool and call its constructor.
2652- * It has the same interface as `rt.lifetime._d_newclass()`.
2653- * `T` must be Throwable or derived from it, must declare an explicit ctor
2654- * and cannot be a COM or C++ class.
2651+ * Allocate an exception of type `T` from the exception pool.
2652+ * `T` must be `Throwable` or derived from it and cannot be a COM or C++ class.
2653+ *
2654+ * Note:
2655+ * This function does not call the constructor of `T` because that would require
2656+ * `forward!args`, which causes errors with -dip1008. This inconvenience will be
2657+ * removed once -dip1008 works as intended.
2658+ *
26552659 * Returns:
2656- * constructed instance of the type
2660+ * allocated instance of type `T`
26572661 */
2658- T _d_newThrowable (T, Args... )(auto ref Args args) @trusted
2659- if (is (T : Throwable) && is (typeof (T.__ctor(forward! args))) &&
2660- __traits(getLinkage, T) == " D" )
2662+ T _d_newThrowable (T)() @trusted
2663+ if (is (T : Throwable) && __traits(getLinkage, T) == " D" )
26612664{
26622665 debug (PRINTF ) printf(" _d_newThrowable(%s)\n " , cast (char * ) T.stringof);
26632666
@@ -2687,33 +2690,22 @@ T _d_newThrowable(T, Args...)(auto ref Args args) @trusted
26872690
26882691 (cast (Throwable) p).refcount() = 1 ;
26892692
2690- auto t = cast (T) p;
2691- t.__ctor(forward! args);
2692-
2693- return t;
2693+ return cast (T) p;
26942694}
26952695
26962696@system unittest
26972697{
26982698 class E : Exception
26992699 {
2700- int x;
2701-
2702- this (int x, string msg = " " , Throwable nextInChain = null )
2700+ this (string msg = " " , Throwable nextInChain = null )
27032701 {
27042702 super (msg, nextInChain);
2705- this .x = x;
27062703 }
27072704 }
27082705
2709- auto exc = _d_newThrowable! Exception (" Exception" );
2710- assert (exc.refcount() == 1 );
2711- assert (exc.msg == " Exception" );
2712-
2713- static assert (! __traits(compiles, _d_newThrowable! E()));
2706+ Throwable exc = _d_newThrowable! Exception ();
2707+ Throwable e = _d_newThrowable! E();
27142708
2715- auto e = _d_newThrowable ! E( 42 , " E " , null );
2709+ assert (exc.refcount() == 1 );
27162710 assert (e.refcount() == 1 );
2717- assert (e.x == 42 );
2718- assert (e.msg == " E" );
27192711}
0 commit comments