Missing compiler warning?

Chris wendlec at tcd.ie
Fri Oct 18 03:41:49 PDT 2013


I had a stupid bug:

class Base {
   SomeStruct someStruct;
   // ...
}

class BaseSub {
   // ...
   override {
     public void doThis() {
       auto someStruct = checkSomething("input"); // Bug is here, 
of course,
                                                  // a leftover 
from old code
     }
   }

   private void doSomethingElse() {
     if (someStruct.hasValue) {
        auto val = someStruct.value; // Segmentation fault (core 
dumped)
        // ...
     }
   }

   private auto someCheck(string input) {
     return SomeStruct(input);
   }
}

dmd 2.63

SomeStruct is declared outside the class.

It compiled and dmd didn't say anything about "local variable 
declaration someStruct is hiding class variable someStruct."

Is it because a) I use it in "override" and/or b) because I 
declare it in the base class but only use it in the subclass (for 
now)? Am I making a mess of scopes and stuff? Or is it a bug?


More information about the Digitalmars-d mailing list