"private:" remains in effect after end of containing attribute{}

Daniel Keep daniel.keep.lists at gmail.com
Fri Apr 6 08:51:05 PDT 2007



Frits van Bommel wrote:
> Something I ran into today:
> =====
> $ cat test.d
> import std.stdio;
> import a;
> 
> void main()
> {
>     auto a = new A;
>     writefln(a.b);
> }
> $ cat a.d
> struct A {
>     final {
>         private:
>         int a;
>     }
>     static bool b;
> }
> $ dmd test.d a.d
> test.d(7): struct a.A member b is not accessible
> =====
> (After commenting out the "private:" line it compiles fine)
> 
> Is that error supposed to happen?
> Shouldn't the one of the block endings stop the "private:" from
> remaining in effect afterwards?
> 
> The spec seems to be very clear on this.
> http://www.digitalmars.com/d/attribute.html says the "attribute:" syntax
> "affects all declarations until the next }".
> 
> (Note that I recently filed bug #1090
> (http://d.puremagic.com/issues/show_bug.cgi?id=1090) to change that
> sentence since as it stands now things like "version(Windows) {
> extern(Windows): }" should technically have no effect on anything,
> though the compiler doesn't implement it that way)
> 
> Since IMHO either that sentence or the compiler should be changed
> anyway, perhaps there should be some discussion about /which/ closing
> }'s should end the effects of an "attribute:" line.
> Any thoughts?

I believe this is because it *should* say: "affects all declarations
until the end of the scope", and "final { ... }" doesn't introduce a scope.

	-- Daniel

-- 
int getRandomNumber()
{
    return 4; // chosen by fair dice roll.
              // guaranteed to be random.
}

http://xkcd.com/

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/



More information about the Digitalmars-d mailing list