www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21197] New: Wrong lifetime inference with DIP1000 in dmd


          Issue ID: 21197
           Summary: Wrong lifetime inference with DIP1000 in dmd 2.093.0
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: atila.neves gmail.com

This is a regression compared to 2.092.1. I don't know how this got past CI
since it broke unit-threaded.

This test compiled with 2.092.1 but fails to do so with 2.092.1:


The reason is the  safe inference done on this template function: 


After investigating and adding  safe to it, the compiler fails to compile it
with this: 

subpackages/property/source/unit_threaded/property.d(48,21): Error: address of
struct temporary returned by createGenerator() assigned to longer lived
variable gen

This is obviously false. Applying this diff makes the problem go away, which is
a valid workaround but that shouldn't be needed:

     // See https://github.com/atilaneves/unit-threaded/issues/187 for why
-    auto createGenerator() {
+    auto createGenerator(ref Random random) {
         return RndValueGen!(Parameters!F)(&random);

     // It might be that some projects don't use dip1000 and so
     // createGenerator isn't safe
     static if(isSafe!createGenerator)
-        scope gen = createGenerator;
+        scope gen = createGenerator(random);
-        scope gen = ()  trusted { return createGenerator; }();
+        scope gen = ()  trusted { return createGenerator(random); }();

     auto input(Flag!"shrink" shrink = Yes.shrink) {

Aug 25 2020