[Issue 21197] New: Wrong lifetime inference with DIP1000 in dmd 2.093.0
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Tue Aug 25 14:26:37 UTC 2020
    
    
  
https://issues.dlang.org/show_bug.cgi?id=21197
          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 at puremagic.com
          Reporter: atila.neves at 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:
https://github.com/atilaneves/unit-threaded/blob/42d517a9bbdfc216fcedf65440c1ec71b437a175/tests/unit_threaded/ut/property.d#L7
The reason is the @safe inference done on this template function: 
https://github.com/atilaneves/unit-threaded/blob/42d517a9bbdfc216fcedf65440c1ec71b437a175/subpackages/property/source/unit_threaded/property.d#L21
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);
     else
-        scope gen = () @trusted { return createGenerator; }();
+        scope gen = () @trusted { return createGenerator(random); }();
     auto input(Flag!"shrink" shrink = Yes.shrink) {
--
    
    
More information about the Digitalmars-d-bugs
mailing list