foreach range construction bug?!!?!?!?

Era Scarecrow rtcvb32 at yahoo.com
Sun Jan 6 15:58:33 PST 2013


On Sunday, 6 January 2013 at 23:16:13 UTC, Phil Lavoie wrote:
> since moving the constructor away seems to work correctly 
> (-version=Working).

  Mmmm... But no construction happens, empty parameters equals 
default .init. Perhaps it's a bug related to confusing 
lvalue/rvalue and it's trying to access a temporary variable 
outside it's scope (so it has garbage data); but even with 
garbage data...

   @property bool empty() {
     writeln("Empty!");
     _current = glGetError();
     return ( _current == GL_NO_ERROR );
   }
   @property GLenum front() {
     writeln("Front!");
     return _current;
   }
   void popFront() { writeln("PopFront!"); }
}

  If it dies before printing 'Empty!' or 'Front!' then it could be 
a temporary reference variable bug (I really doubt ctor, although 
a garbage pointer would cause the problem too).

  If it dies instead at glGetError it likely is a hidden global 
variable is getting messed up/not initialized (though seems 
unlikely).

  Decompile the assembly code around the foreach loop and the 
working version, that will give us a definitive explanation of 
what's really going on.


  Mmmm I wonder... __traits(compiles) allowed me to see a hidden 
added 'void* this;' pointer in a union; Perhaps...

  else {
     //Crashes in non defined version.
     assert(__traits(compiles, {
       foreach( GLenum err; GLErrors() ) {
         const int a;
         a++; // breaking on purpose, may show full unrolling
              // of compiler re-written code
         writeln( glError( err ) );
       }
     }));
  }


More information about the Digitalmars-d-learn mailing list