www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8446] New: Can't use 'this' pointer in pure member function?

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8446

           Summary: Can't use 'this' pointer in pure member function?
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dmitry.olsh gmail.com



13:53:25 PDT ---
A test case, probably can be reduced futher:

 trusted public struct RleBitSet(T)
{
public:
     property auto byInterval() pure const
    {
        static struct IntervalRange
        {
            this(in RleBitSet set_)
            {

            }            
        }
        return IntervalRange(this);
    }

}

immutable set = RleBitSet!(uint).init;

pure void func()
{
    auto x = set.byInterval;    
}


Tested on DMD 2.060 beta. Compiler flags seem to have no effect.

Output:
bug.d(14): Error: pure function 'byInterval' cannot call impure function 'this'

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 26 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8446


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei metalanguage.com
           Severity|normal                      |blocker


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 24 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8446


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID





This is a trivial bug of the original code.

     property auto byInterval() pure const
    {
        static struct IntervalRange
        {
this(in RleBitSet set_) // should be pure
            {
            }            
        }
return IntervalRange(this); // needs pure constructor
    }
-- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 08 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8446




10:50:40 PST ---


 
 This is a trivial bug of the original code.
 
     property auto byInterval() pure const
    {
        static struct IntervalRange
        {
this(in RleBitSet set_) // should be pure
            {
            }            
        }
return IntervalRange(this); // needs pure constructor
    }
Thanks, it's indeed obvious from the perspective. But since this was a parameter, it didn't occur to me it means constructor of IntervalRange that is not pure. Must have been angry already. I'd still argue that error message is not helpful. Error: pure function 'byInterval' cannot call impure function 'this' There is no idication of which 'this' it talks about. Would it be better if it listed IntervalRange.this? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 09 2012