www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4915] New: auto return type escapes function purity

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

           Summary: auto return type escapes function purity
           Product: D
           Version: 2.039
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: tomash.brechko gmail.com


--- Comment #0 from Tomash Brechko <tomash.brechko gmail.com> 2010-09-22
08:03:34 PDT ---
dmd 2.039 doesn't produce error for pure function with auto return type that
violates purity:

int global;

pure auto f()
{
  global = 1;
  return 0;
}

compiles without errors.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 22 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4915


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au


--- Comment #1 from Don <clugdbug yahoo.com.au> 2010-09-22 08:18:15 PDT ---
Actually, the bug is something different:

pure auto f() {  return 0; }
pure int g() { return f(); }

bug.d(3): Error: pure function 'g' cannot call impure function 'f'

The bug is that for 'auto' functions, 'pure' is ignored.
Bug 3359 is another aspect of the same thing. In fact I think there are about
five bugs which probably all have the same root cause.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 22 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4915


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid, patch


--- Comment #2 from Don <clugdbug yahoo.com.au> 2010-11-08 17:43:54 PST ---
This patch also fixes bug 4640, bug 5006, and cases 2 and 3 of bug 3573.

PATCH: func.c,  FuncDeclaration::semantic, line 164. All of the
function-related storage classes need to be applied to the function.
(Possibly STCsynchronised as well? Maybe there should be a #define which puts
all of these together, in case the relevant list gets longer).


    if (!type->deco)
    {
        sc = sc->push();
-        sc->stc |= storage_class & STCref;      // forward to function type
+        sc->stc |= storage_class & (STCref | STCnothrow | STCpure | STCdisable
| STCproperty | STCsafe | STCtrusted | STCsystem);      // forward to function
type
        if (isCtorDeclaration())
            sc->flags |= SCOPEctor;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 08 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4915



--- Comment #3 from Don <clugdbug yahoo.com.au> 2010-11-09 00:14:32 PST ---
Test case (should compile with no errors):

pure nothrow  safe auto bug4915a() {  return 0; }
pure nothrow  safe int  bug4915b() { return bug4915a(); }

void bug4915c()
{
    pure nothrow  safe int d() { return 0; }
    int e() pure nothrow  safe { return d(); }    
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 09 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4915



--- Comment #4 from Don <clugdbug yahoo.com.au> 2010-11-09 05:26:29 PST ---
oops, STCproperty shouldn't be in that list.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 09 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4915


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


--- Comment #5 from Walter Bright <bugzilla digitalmars.com> 2010-11-10
22:21:09 PST ---
http://www.dsource.org/projects/dmd/changeset/748

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 10 2010