www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1894] New: Missed scope guard statements

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

           Summary: Missed scope guard statements
           Product: D
           Version: 2.010
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: sjackso cs.wisc.edu


This snippet:

{
if( true ){ scope(exit) writef("hello"); }
writefln(" world" );
}

Produces the output "hello world", as expected.  However, when the if
statement's braces are removed...

{
if( true ) scope(exit) writef("hello");
writefln( " world" );
}

... then the first writef call is skipped entirely, and the output is " world".
 No errors or compiler warnings are generated.


-- 
Mar 05 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1894





------- Comment #1 from gide nwawudu.com  2008-03-09 11:54 -------
This looks similar to an issue I had with foreach and scope, BUG 1765.


-- 
Mar 09 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1894


Don <clugdbug yahoo.com.au> changed:

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


--- Comment #2 from Don <clugdbug yahoo.com.au> 2009-09-16 07:19:26 PDT ---
Seems to be the same issue as bug 1087.

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


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         OS/Version|Linux                       |All
           Severity|normal                      |blocker


--- Comment #3 from Don <clugdbug yahoo.com.au> 2009-09-16 11:48:04 PDT ---
This is one example of an endemic problem. There's a host of possible test
cases which fail. Basically, OnScopeStatement works ONLY when it is in a
CompoundStatement: it's the only time when scopecode() is called. Everywhere
else, the only thing called is OnScopeStatement::semantic(), which does
nothing.
I think that what should happen, is that since in these cases it's the only
thing in its scope, OnScopeStatement::semantic should either (1) generate an
error; or (2) run semantic on its statement (depending on the type of scopecode
it is).

And labels (bugzilla 1087) should be treated specially, since they are not
really statements themselves.

Here's a non-exhaustive collection of test cases, each of which generate two
asm instructions so that the disassembly is very easy to understand. In each
case, an 'int 3' instruction should appear, but none are present.

This blocks deterministic destruction.
(BTW in each of these cases, in D2, if you replace "scope(exit) asm{int3}" with
"A a;" where A is a struct with a destructor, the compiler segfaults).

---------------------

void bug1087a() { // Bugzilla 1087
    dummylabel:
        scope(exit) 
            asm { int 3; }
}

void bug1087b() { // Bugzilla 1894
    if (true)
        scope(exit) 
            asm { int 3; }
}

void bug1087c() {
    if (false){} else
        scope(exit) 
            asm { int 3; }
}

void bug1087d() {
    while(true)
        scope(exit) 
            asm { int 3; }            
}

void bug1087e() {
    do scope(exit) 
            asm { int 3; }
    while(false)
}

void bug1087f() {
   foreach(x; 1..2) scope(exit) asm {int 3; }
}

void bug1087g() {
   scope(exit) scope(exit) asm {int 3; }
}

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


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|2.010                       |1.010
            Summary|Missed scope guard          |scope(exit) is ignored
                   |statements                  |except in compound
                   |                            |statements


--- Comment #4 from Don <clugdbug yahoo.com.au> 2009-09-16 11:53:18 PDT ---
And it applies equally to D1 (obviously, a couple of the test cases don't
apply).

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



--- Comment #5 from Don <clugdbug yahoo.com.au> 2010-05-22 14:21:41 PDT ---
An interim patch:
To patch the worst instance of this (  if (xxx) scope(exit) yyy;
 creating a error which recommends scope(exit) if (xxx) yyy; ),
 add IsScopeGuardStatement() to Statement and OnScopeStatement, and then
add the following lines to statement.c 2300 (IfStatement::semantic())

    // If we can short-circuit evaluate the if statement, don't do the
    // semantic analysis of the skipped code.
    // This feature allows a limited form of conditional compilation.
    condition = condition->optimize(WANTflags);
+    if (ifbody->IsScopeGuardStatement() ) {
+        OnScopeStatement *onsc = ifbody->IsScopeGuardStatement();
+        IfStatement *iff = new IfStatement(loc, arg, condition,
onsc->statement, elsebody);
+        error("Use of ScopeGuardStatement in otherwise empty scope. Did you
mean\n%s",    
+        (new OnScopeStatement(onsc->loc, onsc->tok, iff))->toChars());
+    }

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jarrett.billingsley gmail.c
                   |                            |om


--- Comment #6 from Walter Bright <bugzilla digitalmars.com> 2010-05-28
21:38:56 PDT ---
*** Issue 1087 has been marked as a duplicate of this issue. ***

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


Walter Bright <bugzilla digitalmars.com> changed:

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


--- Comment #7 from Walter Bright <bugzilla digitalmars.com> 2010-05-28
21:59:12 PDT ---
http://www.dsource.org/projects/dmd/changeset/503

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