www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21850] New: Template inference of pure not working


          Issue ID: 21850
           Summary: Template inference of pure not working
           Product: D
           Version: D2
          Hardware: x86_64
                OS: All
            Status: NEW
          Severity: blocker
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: razvan.nitu1305 gmail.com

struct Strukt2 {                                                                
      this(int* _block) {  }

struct Strukt {
      int* block;
      Strukt2 foo() { return Strukt2(null); }
      alias foo this;

import std.exception : doesPointTo;
bool wrapper(T)(ref T a, ref T b)
      return doesPointTo(a, b);

void johan() pure {
      Strukt a;
      Strukt b;
      assert(wrapper(a, b));           // error wrapper is not pure
      //assert(doesPointTo(a, b));     // fine

doesPointTo [1] is specifically marked as being pure. I tried copy-pasting the
code of doesPointTo into the same file with the wrapper declaration and that
seems to fix the issue, so I assume it has something to do with where the code
is emitted?

This is causing problems in phobos [2] because moveEmplaceImpl's purity is
wrongfully affected by this [3].

[1] https://github.com/dlang/phobos/blob/master/std/exception.d#L1039
[2] https://issues.dlang.org/show_bug.cgi?id=21202
[3] https://github.com/dlang/phobos/blob/master/std/algorithm/mutation.d#L1414

Apr 22 2021